Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add linchpin_mock tests to all gcloud gcp resources #1537

Merged
merged 4 commits into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/source/examples/workspaces/gcloud/linchpin.conf
1 change: 1 addition & 0 deletions linchpin/MockUtils/gcdns_record.data
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"changed": true, "diff": {"before": "", "before_header": "<absent>", "after": {"record": "www1.testlpgcdnszone.com.", "type": "A", "record_data": ["192.0.2.23", "192.0.2.42", "198.51.100.5", "203.0.113.10"], "ttl": 300}, "after_header": "A:www1.testlpgcdnszone.com."}, "state": "present", "record": "www1.testlpgcdnszone.com", "zone": "testlpgcdnszone.com.", "zone_id": "testlpgcdnszone-com", "type": "A", "record_data": ["192.0.2.23", "192.0.2.42", "198.51.100.5", "203.0.113.10"], "ttl": 300, "overwrite": false, "failed": false}
1 change: 1 addition & 0 deletions linchpin/MockUtils/gcdns_zone.data
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"changed": true, "diff": {"before": "", "before_header": "<absent>", "after": {"zone": "testlpgcdnszone.com.", "description": "test"}, "after_header": "testlpgcdnszone.com."}, "state": "present", "zone": "testlpgcdnszone.com.", "description": "test", "failed": false}
1 change: 1 addition & 0 deletions linchpin/MockUtils/gce.data
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"zone": "us-central1-a", "state": "present", "instance_data": [{"image": "centos-7-v20191121", "disks": ["gce-webserver-000"], "machine_type": "f1-micro", "metadata": {}, "name": "gce-webserver-000", "network": "default", "subnetwork": "default", "private_ip": "10.128.0.43", "public_ip": "35.193.250.147", "status": "RUNNING", "tags": [], "zone": "us-central1-a"}], "name": "gce-webserver", "changed": true, "failed": false}
1 change: 1 addition & 0 deletions linchpin/MockUtils/gce_eip.data
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"state": "present", "address": "35.231.149.59", "changed": true, "name": "testgcloudeiplinchpin", "region": "us-east1", "failed": false}
1 change: 1 addition & 0 deletions linchpin/MockUtils/gce_net.data
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"state": "present", "name": "testgcloudlinchpinautonet", "ipv4_range": null, "changed": true, "failed": false}
1 change: 1 addition & 0 deletions linchpin/MockUtils/gcp_compute_network.data
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"id": "911265077410338739", "creationTimestamp": "2019-12-09T12:06:52.730-08:00", "name": "testgcpcomputenetwork", "description": "test_gcp_compute_network_linchpin", "selfLink": "https://www.googleapis.com/compute/v1/projects/linchpin-225218/global/networks/testgcpcomputenetwork", "autoCreateSubnetworks": false, "routingConfig": {"routingMode": "REGIONAL"}, "kind": "compute#network", "changed": true, "failed": false}
1 change: 1 addition & 0 deletions linchpin/MockUtils/gcp_compute_network_facts.data
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"resources": [{"id": "7978328111630717326", "creationTimestamp": "2019-12-09T12:32:33.864-08:00", "name": "tcomputenetwork", "description": "test_gcp_compute_network_linchpin", "selfLink": "https://www.googleapis.com/compute/v1/projects/linchpin-225218/global/networks/tcomputenetwork", "autoCreateSubnetworks": false, "routingConfig": {"routingMode": "REGIONAL"}, "kind": "compute#network"}], "deprecations": [{"msg": "The 'gcp_compute_network_facts' module has been renamed to 'gcp_compute_network_info'", "version": "2.13"}], "failed": false, "changed": false}
1 change: 1 addition & 0 deletions linchpin/MockUtils/gcp_compute_router.data
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"id": "6231353784640147140", "creationTimestamp": "2019-12-09T12:35:55.209-08:00", "name": "tcomputerouter", "region": "https://www.googleapis.com/compute/v1/projects/linchpin-225218/regions/us-central1", "network": "https://www.googleapis.com/compute/v1/projects/linchpin-225218/global/networks/tcomputenetwork", "bgp": {"asn": 64514, "advertiseMode": "CUSTOM", "advertisedGroups": ["ALL_SUBNETS"], "advertisedIpRanges": [{"range": "1.2.3.4"}, {"range": "6.7.0.0/16"}]}, "selfLink": "https://www.googleapis.com/compute/v1/projects/linchpin-225218/regions/us-central1/routers/tcomputerouter", "kind": "compute#router", "changed": true, "failed": false}
30 changes: 30 additions & 0 deletions linchpin/provision/action_plugins/gcdns_record.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

from ansible.plugins.action import ActionBase
import linchpin.MockUtils.MockUtils as mock_utils


class ActionModule(ActionBase):
def run(self, tmp=None, task_vars=None):
"""
Simple action plugin that returns the mocked output
when linchpin_mock is True
"""
super(ActionModule, self).run(tmp, task_vars)
# contains all the module arguments
module_args = self._task.args.copy()
# task vars.keys() contains all the variable required
# when passed a extra_var as key value pair task_vars
# would return mocked output of the named module.
# print(task_vars['vars'].keys())
# print(task_vars['vars'].get('linchpin_mock', False))
linchpin_mock = task_vars['vars'].get('linchpin_mock',
False)
if linchpin_mock:
return mock_utils.get_mock_data(module_args,
"gcdns_record")

module_return = self._execute_module(module_args=module_args,
task_vars=task_vars, tmp=tmp)
return module_return
30 changes: 30 additions & 0 deletions linchpin/provision/action_plugins/gcdns_zone.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

from ansible.plugins.action import ActionBase
import linchpin.MockUtils.MockUtils as mock_utils


class ActionModule(ActionBase):
def run(self, tmp=None, task_vars=None):
"""
Simple action plugin that returns the mocked output
when linchpin_mock is True
"""
super(ActionModule, self).run(tmp, task_vars)
# contains all the module arguments
module_args = self._task.args.copy()
# task vars.keys() contains all the variable required
# when passed a extra_var as key value pair task_vars
# would return mocked output of the named module.
# print(task_vars['vars'].keys())
# print(task_vars['vars'].get('linchpin_mock', False))
linchpin_mock = task_vars['vars'].get('linchpin_mock',
False)
if linchpin_mock:
return mock_utils.get_mock_data(module_args,
"gcdns_zone")

module_return = self._execute_module(module_args=module_args,
task_vars=task_vars, tmp=tmp)
return module_return
30 changes: 30 additions & 0 deletions linchpin/provision/action_plugins/gce.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

from ansible.plugins.action import ActionBase
import linchpin.MockUtils.MockUtils as mock_utils


class ActionModule(ActionBase):
def run(self, tmp=None, task_vars=None):
"""
Simple action plugin that returns the mocked output
when linchpin_mock is True
"""
super(ActionModule, self).run(tmp, task_vars)
# contains all the module arguments
module_args = self._task.args.copy()
# task vars.keys() contains all the variable required
# when passed a extra_var as key value pair task_vars
# would return mocked output of the named module.
# print(task_vars['vars'].keys())
# print(task_vars['vars'].get('linchpin_mock', False))
linchpin_mock = task_vars['vars'].get('linchpin_mock',
False)
if linchpin_mock:
return mock_utils.get_mock_data(module_args,
"gce")

module_return = self._execute_module(module_args=module_args,
task_vars=task_vars, tmp=tmp)
return module_return
30 changes: 30 additions & 0 deletions linchpin/provision/action_plugins/gce_eip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

from ansible.plugins.action import ActionBase
import linchpin.MockUtils.MockUtils as mock_utils


class ActionModule(ActionBase):
def run(self, tmp=None, task_vars=None):
"""
Simple action plugin that returns the mocked output
when linchpin_mock is True
"""
super(ActionModule, self).run(tmp, task_vars)
# contains all the module arguments
module_args = self._task.args.copy()
# task vars.keys() contains all the variable required
# when passed a extra_var as key value pair task_vars
# would return mocked output of the named module.
# print(task_vars['vars'].keys())
# print(task_vars['vars'].get('linchpin_mock', False))
linchpin_mock = task_vars['vars'].get('linchpin_mock',
False)
if linchpin_mock:
return mock_utils.get_mock_data(module_args,
"gce_eip")

module_return = self._execute_module(module_args=module_args,
task_vars=task_vars, tmp=tmp)
return module_return
30 changes: 30 additions & 0 deletions linchpin/provision/action_plugins/gce_net.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

from ansible.plugins.action import ActionBase
import linchpin.MockUtils.MockUtils as mock_utils


class ActionModule(ActionBase):
def run(self, tmp=None, task_vars=None):
"""
Simple action plugin that returns the mocked output
when linchpin_mock is True
"""
super(ActionModule, self).run(tmp, task_vars)
# contains all the module arguments
module_args = self._task.args.copy()
# task vars.keys() contains all the variable required
# when passed a extra_var as key value pair task_vars
# would return mocked output of the named module.
# print(task_vars['vars'].keys())
# print(task_vars['vars'].get('linchpin_mock', False))
linchpin_mock = task_vars['vars'].get('linchpin_mock',
False)
if linchpin_mock:
return mock_utils.get_mock_data(module_args,
"gce_net")

module_return = self._execute_module(module_args=module_args,
task_vars=task_vars, tmp=tmp)
return module_return
30 changes: 30 additions & 0 deletions linchpin/provision/action_plugins/gcp_compute_network.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

from ansible.plugins.action import ActionBase
import linchpin.MockUtils.MockUtils as mock_utils


class ActionModule(ActionBase):
def run(self, tmp=None, task_vars=None):
"""
Simple action plugin that returns the mocked output
when linchpin_mock is True
"""
super(ActionModule, self).run(tmp, task_vars)
# contains all the module arguments
module_args = self._task.args.copy()
# task vars.keys() contains all the variable required
# when passed a extra_var as key value pair task_vars
# would return mocked output of the named module.
# print(task_vars['vars'].keys())
# print(task_vars['vars'].get('linchpin_mock', False))
linchpin_mock = task_vars['vars'].get('linchpin_mock',
False)
if linchpin_mock:
return mock_utils.get_mock_data(module_args,
"gcp_compute_network")

module_return = self._execute_module(module_args=module_args,
task_vars=task_vars, tmp=tmp)
return module_return
30 changes: 30 additions & 0 deletions linchpin/provision/action_plugins/gcp_compute_network_facts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

from ansible.plugins.action import ActionBase
import linchpin.MockUtils.MockUtils as mock_utils


class ActionModule(ActionBase):
def run(self, tmp=None, task_vars=None):
"""
Simple action plugin that returns the mocked output
when linchpin_mock is True
"""
super(ActionModule, self).run(tmp, task_vars)
# contains all the module arguments
module_args = self._task.args.copy()
# task vars.keys() contains all the variable required
# when passed a extra_var as key value pair task_vars
# would return mocked output of the named module.
# print(task_vars['vars'].keys())
# print(task_vars['vars'].get('linchpin_mock', False))
linchpin_mock = task_vars['vars'].get('linchpin_mock',
False)
if linchpin_mock:
return mock_utils.get_mock_data(module_args,
"gcp_compute_network_facts")

module_return = self._execute_module(module_args=module_args,
task_vars=task_vars, tmp=tmp)
return module_return
30 changes: 30 additions & 0 deletions linchpin/provision/action_plugins/gcp_compute_router.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

from ansible.plugins.action import ActionBase
import linchpin.MockUtils.MockUtils as mock_utils


class ActionModule(ActionBase):
def run(self, tmp=None, task_vars=None):
"""
Simple action plugin that returns the mocked output
when linchpin_mock is True
"""
super(ActionModule, self).run(tmp, task_vars)
# contains all the module arguments
module_args = self._task.args.copy()
# task vars.keys() contains all the variable required
# when passed a extra_var as key value pair task_vars
# would return mocked output of the named module.
# print(task_vars['vars'].keys())
# print(task_vars['vars'].get('linchpin_mock', False))
linchpin_mock = task_vars['vars'].get('linchpin_mock',
False)
if linchpin_mock:
return mock_utils.get_mock_data(module_args,
"gcp_compute_router")

module_return = self._execute_module(module_args=module_args,
task_vars=task_vars, tmp=tmp)
return module_return
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@
zone_id: "{{ res_def['zone_id'] | default(omit) }}"
pem_file: "{{ auth_var['output']['pem_file'] | default(omit) }}"
project_id: "{{ auth_var['output']['project_id'] | default(omit) }}"
credentials_file: "{{ auth_var['path'] }}/{{ auth_var['params']['filename'] | default(omit) }}"
credentials_file: "{{ auth_var['path'] | default(omit) }}/{{ auth_var['params']['filename'] | default(omit) }}"
state: "{{ state }}"
service_account_email: "{{ auth_var['output']['client_email'] | default(omit) }}"
register: res_def_output
no_log: "{{ not debug_mode }}"

- debug:
msg: "{{ res_def_output }}"

- name: "Appending outputitem to topology_outputs"
set_fact:
topology_outputs_gcloud_gce: "{{ topology_outputs_gcloud_gce + [res_def_output] }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
zone: "{{ res_def['zone'] | default(res_def['name']) }}"
pem_file: "{{ auth_var['output']['pem_file'] | default(omit) }}"
project_id: "{{ auth_var['output']['project_id'] | default(omit) }}"
credentials_file: "{{ auth_var['path'] }}/{{ auth_var['params']['filename'] | default(omit) }}"
credentials_file: "{{ auth_var['path'] | default(omit) }}/{{ auth_var['params']['filename'] | default(omit) }}"
state: "{{ state }}"
service_account_email: "{{ auth_var['output']['client_email'] | default(omit) }}"
state: "{{ state }}"
description: "{{ res_def['description'] | default(omit) }}"
register: res_def_output
no_log: "{{ not debug_mode }}"

- debug:
msg: "{{ res_def_output }}"

- name: "Appending outputitem to topology_outputs"
set_fact:
topology_outputs_gcloud_gce: "{{ topology_outputs_gcloud_gce + [res_def_output] }}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

- name: "Provision/Teardown resource by looping on count"
gce:
name: "{{ gce_resource_name }}"
Expand All @@ -6,9 +7,9 @@
machine_type: "{{ res_def['flavor'] }}"
image: "{{ res_def['image'] }}"
state: "{{ state }}"
service_account_email: "{{ auth_var['output']['client_email'] }}"
credentials_file: "{{ auth_var['path'] }}/{{ auth_var['params']['filename'] }}"
project_id: "{{ auth_var['output']['project_id'] }}"
service_account_email: "{{ auth_var['output']['client_email'] | default(omit) }}"
credentials_file: "{{ auth_var['path'] | default(omit) }}/{{ auth_var['params']['filename'] | default(omit) }}"
project_id: "{{ auth_var['output']['project_id'] | default(omit) }}"
tags: "{{ res_def['tags'] | default(omit) }}"
register: res_def_output
when: not _async
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
name: "{{ gce_resource_name }}"
state: "{{ state }}"
region: "{{ res_def['region'] }}"
service_account_email: "{{ auth_var['output']['client_email'] }}"
credentials_file: "{{ auth_var['path'] }}/{{ auth_var['params']['filename'] }}"
project_id: "{{ auth_var['output']['project_id'] }}"
service_account_email: "{{ auth_var['output']['client_email'] | default(omit) }}"
credentials_file: "{{ auth_var['path'] | default(omit) }}/{{ auth_var['params']['filename'] | default(omit) }}"
project_id: "{{ auth_var['output']['project_id'] | default(omit) }}"
register: res_def_output
no_log: "{{ not debug_mode }}"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
mode: "{{ res_def['mode'] | default(omit) }}"
pem_file: "{{ auth_var['output']['pem_file'] | default(omit) }}"
project_id: "{{ auth_var['output']['project_id'] | default(omit) }}"
credentials_file: "{{ auth_var['path'] }}/{{ auth_var['params']['filename'] | default(omit) }}"
credentials_file: "{{ auth_var['path'] | default(omit) }}/{{ auth_var['params']['filename'] | default(omit) }}"
state: "{{ state }}"
subnet_region: "{{ res_def['subent_region'] | default(omit) }}"
service_account_email: "{{ auth_var['output']['client_email'] | default(omit) }}"
Expand All @@ -21,9 +21,6 @@
register: res_def_output
no_log: "{{ not debug_mode }}"

- debug:
msg: "{{ res_def_output }}"

- name: "Appending outputitem to topology_outputs"
set_fact:
topology_outputs_gcloud_gce: "{{ topology_outputs_gcloud_gce + [res_def_output] }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
ipv4_range: "{{ res_def['ipv4_range'] | default(omit) }}"
project: "{{ auth_var['output']['project_id'] | default(omit) }}"
scopes: "{{ res_def['scopes'] | default(['https://www.googleapis.com/auth/compute']) }}"
service_account_file: "{{ auth_var['path'] }}/{{ auth_var['params']['filename'] | default(omit) }}"
service_account_file: "{{ auth_var['path'] | default(omit) }}/{{ auth_var['params']['filename'] | default(omit) }}"
state: "{{ state }}"
register: res_def_output
no_log: "{{ not debug_mode }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
project: "{{ auth_var['output']['project_id'] | default(omit) }}"
auth_kind: "{{ auth_var['output']['auth_kind'] | default('serviceaccount') }}"
scopes: "{{ res_def['scopes'] | default(['https://www.googleapis.com/auth/compute']) }}"
service_account_file: "{{ auth_var['path'] }}/{{ auth_var['params']['filename'] | default(omit) }}"
service_account_file: "{{ auth_var['path'] | default(omit) }}/{{ auth_var['params']['filename'] | default(omit) }}"
register: network_facts_fetched

- name: "Provision/Teardown gcloud_gcp_compute_router"
gcp_compute_router:
name: "{{ res_def['name'] }}"
network: "{{ network_facts_fetched['items'][0] }}"
network: "{{ network_facts_fetched['resources'][0] }}"
bgp: "{{ res_def['bgp'] }}"
region: "{{ res_def['region'] }}"
scopes: "{{ res_def['scopes'] | default(['https://www.googleapis.com/auth/compute']) }}"
service_account_email: "{{ auth_var['output']['service_account_email'] | default(omit) }}"
project: "{{ auth_var['output']['project_id'] | default(omit) }}"
auth_kind: "{{ auth_var['output']['auth_kind'] | default('serviceaccount') }}"
service_account_file: "{{ auth_var['path'] }}/{{ auth_var['params']['filename'] | default(omit) }}"
service_account_file: "{{ auth_var['path'] | default(omit) }}/{{ auth_var['params']['filename'] | default(omit) }}"
state: "{{ state }}"
register: res_def_output
no_log: "{{ not debug_mode }}"
Expand Down
Loading