mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-27 18:50:21 -07:00
Remove google plugins and set up redirects to collections (#1319)
* Remove Google cloud plugins migrated to community.google * Remove another symlink * Fix typo for community.general version * Update changelogs/fragments/1319-google-migration-removal.yml Co-authored-by: Felix Fontein <felix@fontein.de> * Update changelogs/fragments/1319-google-migration-removal.yml Co-authored-by: Felix Fontein <felix@fontein.de> * Add fragment for inventory script * fix yaml formatting * adjust past relnotes in accordance with removal of google plugins Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
818cafc580
commit
f78e08bc37
51 changed files with 54 additions and 7255 deletions
|
@ -1,162 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# (c) 2016, Tom Melendez (@supertom) <tom@supertom.com>
|
||||
#
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
||||
from ansible_collections.community.general.tests.unit.compat import mock, unittest
|
||||
from ansible_collections.community.general.plugins.module_utils.gcp import (_get_gcp_ansible_credentials, _get_gcp_credentials, _get_gcp_environ_var,
|
||||
_get_gcp_environment_credentials,
|
||||
_validate_credentials_file)
|
||||
|
||||
# Fake data/function used for testing
|
||||
fake_env_data = {'GCE_EMAIL': 'gce-email'}
|
||||
|
||||
|
||||
def fake_get_gcp_environ_var(var_name, default_value):
|
||||
if var_name not in fake_env_data:
|
||||
return default_value
|
||||
else:
|
||||
return fake_env_data[var_name]
|
||||
|
||||
# Fake AnsibleModule for use in tests
|
||||
|
||||
|
||||
class FakeModule(object):
|
||||
class Params():
|
||||
data = {}
|
||||
|
||||
def get(self, key, alt=None):
|
||||
if key in self.data:
|
||||
return self.data[key]
|
||||
else:
|
||||
return alt
|
||||
|
||||
def __init__(self, data=None):
|
||||
data = {} if data is None else data
|
||||
|
||||
self.params = FakeModule.Params()
|
||||
self.params.data = data
|
||||
|
||||
def fail_json(self, **kwargs):
|
||||
raise ValueError("fail_json")
|
||||
|
||||
def deprecate(self, **kwargs):
|
||||
return None
|
||||
|
||||
|
||||
class GCPAuthTestCase(unittest.TestCase):
|
||||
"""Tests to verify different Auth mechanisms."""
|
||||
|
||||
def setup_method(self, method):
|
||||
global fake_env_data
|
||||
fake_env_data = {'GCE_EMAIL': 'gce-email'}
|
||||
|
||||
def test_get_gcp_ansible_credentials(self):
|
||||
input_data = {'service_account_email': 'mysa',
|
||||
'credentials_file': 'path-to-file.json',
|
||||
'project_id': 'my-cool-project'}
|
||||
|
||||
module = FakeModule(input_data)
|
||||
actual = _get_gcp_ansible_credentials(module)
|
||||
expected = tuple(input_data.values())
|
||||
self.assertEqual(sorted(expected), sorted(actual))
|
||||
|
||||
def test_get_gcp_environ_var(self):
|
||||
# Chose not to mock this so we could really verify that it
|
||||
# works as expected.
|
||||
existing_var_name = 'gcp_ansible_auth_test_54321'
|
||||
non_existing_var_name = 'doesnt_exist_gcp_ansible_auth_test_12345'
|
||||
os.environ[existing_var_name] = 'foobar'
|
||||
self.assertEqual('foobar', _get_gcp_environ_var(
|
||||
existing_var_name, None))
|
||||
del os.environ[existing_var_name]
|
||||
self.assertEqual('default_value', _get_gcp_environ_var(
|
||||
non_existing_var_name, 'default_value'))
|
||||
|
||||
def test_validate_credentials_file(self):
|
||||
# TODO(supertom): Only dealing with p12 here, check the other states
|
||||
# of this function
|
||||
module = FakeModule()
|
||||
with mock.patch('ansible_collections.community.general.plugins.module_utils.gcp.open',
|
||||
mock.mock_open(read_data='foobar'), create=True):
|
||||
# pem condition, warning is suppressed with the return_value
|
||||
credentials_file = '/foopath/pem.pem'
|
||||
with self.assertRaises(ValueError):
|
||||
_validate_credentials_file(module,
|
||||
credentials_file=credentials_file,
|
||||
require_valid_json=False,
|
||||
check_libcloud=False)
|
||||
|
||||
@mock.patch('ansible_collections.community.general.plugins.module_utils.gcp._get_gcp_environ_var',
|
||||
side_effect=fake_get_gcp_environ_var)
|
||||
def test_get_gcp_environment_credentials(self, mockobj):
|
||||
global fake_env_data
|
||||
|
||||
actual = _get_gcp_environment_credentials(None, None, None)
|
||||
expected = tuple(['gce-email', None, None])
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
fake_env_data = {'GCE_PEM_FILE_PATH': '/path/to/pem.pem'}
|
||||
expected = tuple([None, '/path/to/pem.pem', None])
|
||||
actual = _get_gcp_environment_credentials(None, None, None)
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
# pem and creds are set, expect creds
|
||||
fake_env_data = {'GCE_PEM_FILE_PATH': '/path/to/pem.pem',
|
||||
'GCE_CREDENTIALS_FILE_PATH': '/path/to/creds.json'}
|
||||
expected = tuple([None, '/path/to/creds.json', None])
|
||||
actual = _get_gcp_environment_credentials(None, None, None)
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
# expect GOOGLE_APPLICATION_CREDENTIALS over PEM
|
||||
fake_env_data = {'GCE_PEM_FILE_PATH': '/path/to/pem.pem',
|
||||
'GOOGLE_APPLICATION_CREDENTIALS': '/path/to/appcreds.json'}
|
||||
expected = tuple([None, '/path/to/appcreds.json', None])
|
||||
actual = _get_gcp_environment_credentials(None, None, None)
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
# project tests
|
||||
fake_env_data = {'GCE_PROJECT': 'my-project'}
|
||||
expected = tuple([None, None, 'my-project'])
|
||||
actual = _get_gcp_environment_credentials(None, None, None)
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
fake_env_data = {'GOOGLE_CLOUD_PROJECT': 'my-cloud-project'}
|
||||
expected = tuple([None, None, 'my-cloud-project'])
|
||||
actual = _get_gcp_environment_credentials(None, None, None)
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
# data passed in, picking up project id only
|
||||
fake_env_data = {'GOOGLE_CLOUD_PROJECT': 'my-project'}
|
||||
expected = tuple(['my-sa-email', '/path/to/creds.json', 'my-project'])
|
||||
actual = _get_gcp_environment_credentials(
|
||||
'my-sa-email', '/path/to/creds.json', None)
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
@mock.patch('ansible_collections.community.general.plugins.module_utils.gcp._get_gcp_environ_var',
|
||||
side_effect=fake_get_gcp_environ_var)
|
||||
def test_get_gcp_credentials(self, mockobj):
|
||||
global fake_env_data
|
||||
|
||||
fake_env_data = {}
|
||||
module = FakeModule()
|
||||
module.params.data = {}
|
||||
# Nothing is set, calls fail_json
|
||||
with pytest.raises(ValueError):
|
||||
_get_gcp_credentials(module)
|
||||
|
||||
# project_id (only) is set from Ansible params.
|
||||
module.params.data['project_id'] = 'my-project'
|
||||
actual = _get_gcp_credentials(
|
||||
module, require_valid_json=True, check_libcloud=False)
|
||||
expected = {'service_account_email': '',
|
||||
'project_id': 'my-project',
|
||||
'credentials_file': ''}
|
||||
self.assertEqual(expected, actual)
|
|
@ -1,361 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# (c) 2016, Tom Melendez <tom@supertom.com>
|
||||
#
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible_collections.community.general.tests.unit.compat import mock, unittest
|
||||
from ansible_collections.community.general.plugins.module_utils.gcp import check_min_pkg_version, GCPUtils, GCPInvalidURLError
|
||||
|
||||
|
||||
def build_distribution(version):
|
||||
obj = mock.MagicMock()
|
||||
obj.version = '0.5.0'
|
||||
return obj
|
||||
|
||||
|
||||
class GCPUtilsTestCase(unittest.TestCase):
|
||||
params_dict = {
|
||||
'url_map_name': 'foo_url_map_name',
|
||||
'description': 'foo_url_map description',
|
||||
'host_rules': [
|
||||
{
|
||||
'description': 'host rules description',
|
||||
'hosts': [
|
||||
'www.example.com',
|
||||
'www2.example.com'
|
||||
],
|
||||
'path_matcher': 'host_rules_path_matcher'
|
||||
}
|
||||
],
|
||||
'path_matchers': [
|
||||
{
|
||||
'name': 'path_matcher_one',
|
||||
'description': 'path matcher one',
|
||||
'defaultService': 'bes-pathmatcher-one-default',
|
||||
'pathRules': [
|
||||
{
|
||||
'service': 'my-one-bes',
|
||||
'paths': [
|
||||
'/',
|
||||
'/aboutus'
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'name': 'path_matcher_two',
|
||||
'description': 'path matcher two',
|
||||
'defaultService': 'bes-pathmatcher-two-default',
|
||||
'pathRules': [
|
||||
{
|
||||
'service': 'my-two-bes',
|
||||
'paths': [
|
||||
'/webapp',
|
||||
'/graphs'
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@mock.patch("pkg_resources.get_distribution", side_effect=build_distribution)
|
||||
def test_check_minimum_pkg_version(self, mockobj):
|
||||
self.assertTrue(check_min_pkg_version('foobar', '0.4.0'))
|
||||
self.assertTrue(check_min_pkg_version('foobar', '0.5.0'))
|
||||
self.assertFalse(check_min_pkg_version('foobar', '0.6.0'))
|
||||
|
||||
def test_parse_gcp_url(self):
|
||||
# region, resource, entity, method
|
||||
input_url = 'https://www.googleapis.com/compute/v1/projects/myproject/regions/us-east1/instanceGroupManagers/my-mig/recreateInstances'
|
||||
actual = GCPUtils.parse_gcp_url(input_url)
|
||||
self.assertEqual('compute', actual['service'])
|
||||
self.assertEqual('v1', actual['api_version'])
|
||||
self.assertEqual('myproject', actual['project'])
|
||||
self.assertEqual('us-east1', actual['region'])
|
||||
self.assertEqual('instanceGroupManagers', actual['resource_name'])
|
||||
self.assertEqual('my-mig', actual['entity_name'])
|
||||
self.assertEqual('recreateInstances', actual['method_name'])
|
||||
|
||||
# zone, resource, entity, method
|
||||
input_url = 'https://www.googleapis.com/compute/v1/projects/myproject/zones/us-east1-c/instanceGroupManagers/my-mig/recreateInstances'
|
||||
actual = GCPUtils.parse_gcp_url(input_url)
|
||||
self.assertEqual('compute', actual['service'])
|
||||
self.assertEqual('v1', actual['api_version'])
|
||||
self.assertEqual('myproject', actual['project'])
|
||||
self.assertEqual('us-east1-c', actual['zone'])
|
||||
self.assertEqual('instanceGroupManagers', actual['resource_name'])
|
||||
self.assertEqual('my-mig', actual['entity_name'])
|
||||
self.assertEqual('recreateInstances', actual['method_name'])
|
||||
|
||||
# global, resource
|
||||
input_url = 'https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps'
|
||||
actual = GCPUtils.parse_gcp_url(input_url)
|
||||
self.assertEqual('compute', actual['service'])
|
||||
self.assertEqual('v1', actual['api_version'])
|
||||
self.assertEqual('myproject', actual['project'])
|
||||
self.assertTrue('global' in actual)
|
||||
self.assertTrue(actual['global'])
|
||||
self.assertEqual('urlMaps', actual['resource_name'])
|
||||
|
||||
# global, resource, entity
|
||||
input_url = 'https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps/my-url-map'
|
||||
actual = GCPUtils.parse_gcp_url(input_url)
|
||||
self.assertEqual('myproject', actual['project'])
|
||||
self.assertTrue('global' in actual)
|
||||
self.assertTrue(actual['global'])
|
||||
self.assertEqual('v1', actual['api_version'])
|
||||
self.assertEqual('compute', actual['service'])
|
||||
|
||||
# global URL, resource, entity, method_name
|
||||
input_url = 'https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/mybackendservice/getHealth'
|
||||
actual = GCPUtils.parse_gcp_url(input_url)
|
||||
self.assertEqual('compute', actual['service'])
|
||||
self.assertEqual('v1', actual['api_version'])
|
||||
self.assertEqual('myproject', actual['project'])
|
||||
self.assertTrue('global' in actual)
|
||||
self.assertTrue(actual['global'])
|
||||
self.assertEqual('backendServices', actual['resource_name'])
|
||||
self.assertEqual('mybackendservice', actual['entity_name'])
|
||||
self.assertEqual('getHealth', actual['method_name'])
|
||||
|
||||
# no location in URL
|
||||
input_url = 'https://www.googleapis.com/compute/v1/projects/myproject/targetHttpProxies/mytargetproxy/setUrlMap'
|
||||
actual = GCPUtils.parse_gcp_url(input_url)
|
||||
self.assertEqual('compute', actual['service'])
|
||||
self.assertEqual('v1', actual['api_version'])
|
||||
self.assertEqual('myproject', actual['project'])
|
||||
self.assertFalse('global' in actual)
|
||||
self.assertEqual('targetHttpProxies', actual['resource_name'])
|
||||
self.assertEqual('mytargetproxy', actual['entity_name'])
|
||||
self.assertEqual('setUrlMap', actual['method_name'])
|
||||
|
||||
input_url = 'https://www.googleapis.com/compute/v1/projects/myproject/targetHttpProxies/mytargetproxy'
|
||||
actual = GCPUtils.parse_gcp_url(input_url)
|
||||
self.assertEqual('compute', actual['service'])
|
||||
self.assertEqual('v1', actual['api_version'])
|
||||
self.assertEqual('myproject', actual['project'])
|
||||
self.assertFalse('global' in actual)
|
||||
self.assertEqual('targetHttpProxies', actual['resource_name'])
|
||||
self.assertEqual('mytargetproxy', actual['entity_name'])
|
||||
|
||||
input_url = 'https://www.googleapis.com/compute/v1/projects/myproject/targetHttpProxies'
|
||||
actual = GCPUtils.parse_gcp_url(input_url)
|
||||
self.assertEqual('compute', actual['service'])
|
||||
self.assertEqual('v1', actual['api_version'])
|
||||
self.assertEqual('myproject', actual['project'])
|
||||
self.assertFalse('global' in actual)
|
||||
self.assertEqual('targetHttpProxies', actual['resource_name'])
|
||||
|
||||
# test exceptions
|
||||
no_projects_input_url = 'https://www.googleapis.com/compute/v1/not-projects/myproject/global/backendServices/mybackendservice/getHealth'
|
||||
no_resource_input_url = 'https://www.googleapis.com/compute/v1/not-projects/myproject/global'
|
||||
|
||||
no_resource_no_loc_input_url = 'https://www.googleapis.com/compute/v1/not-projects/myproject'
|
||||
|
||||
with self.assertRaises(GCPInvalidURLError) as cm:
|
||||
GCPUtils.parse_gcp_url(no_projects_input_url)
|
||||
self.assertTrue(cm.exception, GCPInvalidURLError)
|
||||
|
||||
with self.assertRaises(GCPInvalidURLError) as cm:
|
||||
GCPUtils.parse_gcp_url(no_resource_input_url)
|
||||
self.assertTrue(cm.exception, GCPInvalidURLError)
|
||||
|
||||
with self.assertRaises(GCPInvalidURLError) as cm:
|
||||
GCPUtils.parse_gcp_url(no_resource_no_loc_input_url)
|
||||
self.assertTrue(cm.exception, GCPInvalidURLError)
|
||||
|
||||
def test_params_to_gcp_dict(self):
|
||||
|
||||
expected = {
|
||||
'description': 'foo_url_map description',
|
||||
'hostRules': [
|
||||
{
|
||||
'description': 'host rules description',
|
||||
'hosts': [
|
||||
'www.example.com',
|
||||
'www2.example.com'
|
||||
],
|
||||
'pathMatcher': 'host_rules_path_matcher'
|
||||
}
|
||||
],
|
||||
'name': 'foo_url_map_name',
|
||||
'pathMatchers': [
|
||||
{
|
||||
'defaultService': 'bes-pathmatcher-one-default',
|
||||
'description': 'path matcher one',
|
||||
'name': 'path_matcher_one',
|
||||
'pathRules': [
|
||||
{
|
||||
'paths': [
|
||||
'/',
|
||||
'/aboutus'
|
||||
],
|
||||
'service': 'my-one-bes'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'defaultService': 'bes-pathmatcher-two-default',
|
||||
'description': 'path matcher two',
|
||||
'name': 'path_matcher_two',
|
||||
'pathRules': [
|
||||
{
|
||||
'paths': [
|
||||
'/webapp',
|
||||
'/graphs'
|
||||
],
|
||||
'service': 'my-two-bes'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
actual = GCPUtils.params_to_gcp_dict(self.params_dict, 'url_map_name')
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
def test_get_gcp_resource_from_methodId(self):
|
||||
input_data = 'compute.urlMaps.list'
|
||||
actual = GCPUtils.get_gcp_resource_from_methodId(input_data)
|
||||
self.assertEqual('urlMaps', actual)
|
||||
input_data = None
|
||||
actual = GCPUtils.get_gcp_resource_from_methodId(input_data)
|
||||
self.assertFalse(actual)
|
||||
input_data = 666
|
||||
actual = GCPUtils.get_gcp_resource_from_methodId(input_data)
|
||||
self.assertFalse(actual)
|
||||
|
||||
def test_get_entity_name_from_resource_name(self):
|
||||
input_data = 'urlMaps'
|
||||
actual = GCPUtils.get_entity_name_from_resource_name(input_data)
|
||||
self.assertEqual('urlMap', actual)
|
||||
input_data = 'targetHttpProxies'
|
||||
actual = GCPUtils.get_entity_name_from_resource_name(input_data)
|
||||
self.assertEqual('targetHttpProxy', actual)
|
||||
input_data = 'globalForwardingRules'
|
||||
actual = GCPUtils.get_entity_name_from_resource_name(input_data)
|
||||
self.assertEqual('forwardingRule', actual)
|
||||
input_data = ''
|
||||
actual = GCPUtils.get_entity_name_from_resource_name(input_data)
|
||||
self.assertEqual(None, actual)
|
||||
input_data = 666
|
||||
actual = GCPUtils.get_entity_name_from_resource_name(input_data)
|
||||
self.assertEqual(None, actual)
|
||||
|
||||
def test_are_params_equal(self):
|
||||
params1 = {'one': 1}
|
||||
params2 = {'one': 1}
|
||||
actual = GCPUtils.are_params_equal(params1, params2)
|
||||
self.assertTrue(actual)
|
||||
|
||||
params1 = {'one': 1}
|
||||
params2 = {'two': 2}
|
||||
actual = GCPUtils.are_params_equal(params1, params2)
|
||||
self.assertFalse(actual)
|
||||
|
||||
params1 = {'three': 3, 'two': 2, 'one': 1}
|
||||
params2 = {'one': 1, 'two': 2, 'three': 3}
|
||||
actual = GCPUtils.are_params_equal(params1, params2)
|
||||
self.assertTrue(actual)
|
||||
|
||||
params1 = {
|
||||
"creationTimestamp": "2017-04-21T11:19:20.718-07:00",
|
||||
"defaultService": "https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/default-backend-service",
|
||||
"description": "",
|
||||
"fingerprint": "ickr_pwlZPU=",
|
||||
"hostRules": [
|
||||
{
|
||||
"description": "",
|
||||
"hosts": [
|
||||
"*."
|
||||
],
|
||||
"pathMatcher": "path-matcher-one"
|
||||
}
|
||||
],
|
||||
"id": "8566395781175047111",
|
||||
"kind": "compute#urlMap",
|
||||
"name": "newtesturlmap-foo",
|
||||
"pathMatchers": [
|
||||
{
|
||||
"defaultService": "https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/bes-pathmatcher-one-default",
|
||||
"description": "path matcher one",
|
||||
"name": "path-matcher-one",
|
||||
"pathRules": [
|
||||
{
|
||||
"paths": [
|
||||
"/data",
|
||||
"/aboutus"
|
||||
],
|
||||
"service": "https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/my-one-bes"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps/newtesturlmap-foo"
|
||||
}
|
||||
params2 = {
|
||||
"defaultService": "https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/default-backend-service",
|
||||
"hostRules": [
|
||||
{
|
||||
"description": "",
|
||||
"hosts": [
|
||||
"*."
|
||||
],
|
||||
"pathMatcher": "path-matcher-one"
|
||||
}
|
||||
],
|
||||
"name": "newtesturlmap-foo",
|
||||
"pathMatchers": [
|
||||
{
|
||||
"defaultService": "https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/bes-pathmatcher-one-default",
|
||||
"description": "path matcher one",
|
||||
"name": "path-matcher-one",
|
||||
"pathRules": [
|
||||
{
|
||||
"paths": [
|
||||
"/data",
|
||||
"/aboutus"
|
||||
],
|
||||
"service": "https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/my-one-bes"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
}
|
||||
|
||||
# params1 has exclude fields, params2 doesn't. Should be equal
|
||||
actual = GCPUtils.are_params_equal(params1, params2)
|
||||
self.assertTrue(actual)
|
||||
|
||||
def test_filter_gcp_fields(self):
|
||||
input_data = {
|
||||
u'kind': u'compute#httpsHealthCheck',
|
||||
u'description': u'',
|
||||
u'timeoutSec': 5,
|
||||
u'checkIntervalSec': 5,
|
||||
u'port': 443,
|
||||
u'healthyThreshold': 2,
|
||||
u'host': u'',
|
||||
u'requestPath': u'/',
|
||||
u'unhealthyThreshold': 2,
|
||||
u'creationTimestamp': u'2017-05-16T15:09:36.546-07:00',
|
||||
u'id': u'8727093129334146639',
|
||||
u'selfLink': u'https://www.googleapis.com/compute/v1/projects/myproject/global/httpsHealthChecks/myhealthcheck',
|
||||
u'name': u'myhealthcheck'}
|
||||
|
||||
expected = {
|
||||
'name': 'myhealthcheck',
|
||||
'checkIntervalSec': 5,
|
||||
'port': 443,
|
||||
'unhealthyThreshold': 2,
|
||||
'healthyThreshold': 2,
|
||||
'host': '',
|
||||
'timeoutSec': 5,
|
||||
'requestPath': '/'}
|
||||
|
||||
actual = GCPUtils.filter_gcp_fields(input_data)
|
||||
self.assertEqual(expected, actual)
|
|
@ -1,66 +0,0 @@
|
|||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import unittest
|
||||
|
||||
from ansible_collections.community.general.plugins.modules.cloud.google.gce_tag import _get_changed_items, _intersect_items, _union_items
|
||||
|
||||
|
||||
class TestGCETag(unittest.TestCase):
|
||||
"""Unit tests for gce_tag module."""
|
||||
|
||||
def test_union_items(self):
|
||||
"""
|
||||
Combine items in both lists
|
||||
removing duplicates.
|
||||
"""
|
||||
listA = [1, 2, 3, 4, 5, 8, 9]
|
||||
listB = [1, 2, 3, 4, 5, 6, 7]
|
||||
want = [1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
got = _union_items(listA, listB)
|
||||
self.assertEqual(want, got)
|
||||
|
||||
def test_intersect_items(self):
|
||||
"""
|
||||
All unique items from either list.
|
||||
"""
|
||||
listA = [1, 2, 3, 4, 5, 8, 9]
|
||||
listB = [1, 2, 3, 4, 5, 6, 7]
|
||||
want = [1, 2, 3, 4, 5]
|
||||
got = _intersect_items(listA, listB)
|
||||
self.assertEqual(want, got)
|
||||
|
||||
# tags removed
|
||||
new_tags = ['one', 'two']
|
||||
existing_tags = ['two']
|
||||
want = ['two'] # only remove the tag that was present
|
||||
got = _intersect_items(existing_tags, new_tags)
|
||||
self.assertEqual(want, got)
|
||||
|
||||
def test_get_changed_items(self):
|
||||
"""
|
||||
All the items from left list that don't match
|
||||
any item from the right list.
|
||||
"""
|
||||
listA = [1, 2, 3, 4, 5, 8, 9]
|
||||
listB = [1, 2, 3, 4, 5, 6, 7]
|
||||
want = [8, 9]
|
||||
got = _get_changed_items(listA, listB)
|
||||
self.assertEqual(want, got)
|
||||
|
||||
# simulate new tags added
|
||||
tags_to_add = ['one', 'two']
|
||||
existing_tags = ['two']
|
||||
want = ['one']
|
||||
got = _get_changed_items(tags_to_add, existing_tags)
|
||||
self.assertEqual(want, got)
|
||||
|
||||
# simulate removing tags
|
||||
# specifying one tag on right that doesn't exist
|
||||
tags_to_remove = ['one', 'two']
|
||||
existing_tags = ['two', 'three']
|
||||
want = ['three']
|
||||
got = _get_changed_items(existing_tags, tags_to_remove)
|
||||
self.assertEqual(want, got)
|
Loading…
Add table
Add a link
Reference in a new issue