Skip to content

Commit

Permalink
updated rel_type enforced (#211)
Browse files Browse the repository at this point in the history
* updated rel_type enforced

* bumped version

* fix tests

* bumbp version

* switched deprecated node types

* flake8

* fix backward comp to past nodes

* fix backward comp to past nodes

* flake8
  • Loading branch information
kaplanyaniv committed Jun 5, 2023
1 parent 64431ac commit dee47f5
Show file tree
Hide file tree
Showing 17 changed files with 73 additions and 47 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
1.9.3: fixed relationships validation of subnetworks.
1.9.2: Use DSL 1.5 plugin yaml.
1.9.1: add __version__.py file in cloudify_gcp folder.
1.9.0: RD-6611 update google auth library in gcp
Expand Down
2 changes: 1 addition & 1 deletion cloudify_gcp/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = '1.9.2'
version = '1.9.3'
9 changes: 6 additions & 3 deletions cloudify_gcp/compute/forwarding_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def creation_validation(**kwargs):
raise NonRecoverableError(
'Must supply a target proxy, '
'either using the `target_proxy` property '
'or the `cloudify.gcp.relationships.'
'or the `cloudify.relationships.gcp.'
'forwarding_rule_connected_to_target_proxy` relationship.')


Expand All @@ -159,8 +159,11 @@ def create(name, region, scheme, ports, network, subnet, backend_service,
if not target_proxy and scheme.lower() != 'internal':
rel = utils.get_relationships(
ctx,
filter_relationships='cloudify.gcp.relationships.'
'forwarding_rule_connected_to_target_proxy')[0]
filter_relationships=[
'cloudify.relationships.gcp.'
'forwarding_rule_connected_to_target_proxy',
'cloudify.gcp.relationships.'
'forwarding_rule_connected_to_target_proxy'])[0]
target_proxy = rel.target.instance.runtime_properties['selfLink']

forwarding_rule = ForwardingRule(
Expand Down
16 changes: 11 additions & 5 deletions cloudify_gcp/compute/global_forwarding_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,18 @@ def creation_validation(**kwargs):
if not props['target_proxy']:
rels = utils.get_relationships(
ctx,
filter_relationships='cloudify.gcp.relationships.'
'forwarding_rule_connected_to_target_proxy',
filter_relationships=['cloudify.relationships.gcp.'
'forwarding_rule_connected_to_target_proxy',
'cloudify.gcp.relationships.'
'forwarding_rule_connected_to_target_proxy'
],
filter_resource_types=['cloudify.nodes.gcp.TargetProxy',
'cloudify.gcp.nodes.TargetProxy'])
if not rels:
raise NonRecoverableError(
'Must supply a target proxy, '
'either using the `target_proxy` property '
'or the `cloudify.gcp.relationships.'
'or the `cloudify.relationships.gcp.'
'forwarding_rule_connected_to_target_proxy` relationship.')


Expand All @@ -115,8 +118,11 @@ def create(name, target_proxy, port_range,
if not target_proxy:
rel = utils.get_relationships(
ctx,
filter_relationships='cloudify.gcp.relationships.'
'forwarding_rule_connected_to_target_proxy')[0]
filter_relationships=[
'cloudify.relationships.gcp'
'.forwarding_rule_connected_to_target_proxy',
'cloudify.gcp.relationships'
'.forwarding_rule_connected_to_target_proxy'])[0]
target_proxy = rel.target.instance.runtime_properties['selfLink']

forwarding_rule = GlobalForwardingRule(
Expand Down
11 changes: 7 additions & 4 deletions cloudify_gcp/compute/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,9 +619,11 @@ def add_external_ip(instance_name, zone, **kwargs):
if not ip_address:
raise GCPError('{} is set, but ip_address is not set'
.format(constants.USE_EXTERNAL_RESOURCE))
elif ip_node.type == 'cloudify.gcp.nodes.Address':
elif ip_node.type in ['cloudify.gcp.nodes.Address',
'cloudify.nodes.gcp.Address']:
ip_address = ctx.target.instance.runtime_properties['address']
elif ip_node.type != 'cloudify.gcp.nodes.ExternalIP':
elif ip_node.type not in ['cloudify.gcp.nodes.ExternalIP',
'cloudify.nodes.gcp.ExternalIP']:
raise NonRecoverableError(
'Incorrect node type ({}) used as Instance external IP'.format(
ip_node.type,
Expand Down Expand Up @@ -738,8 +740,9 @@ def get_ssh_keys():
def validate_contained_in_network(**kwargs):
rels = utils.get_relationships(
ctx,
filter_relationships='cloudify.gcp.relationships.'
'instance_contained_in_network',
filter_relationships=[
'cloudify.relationships.gcp.instance_contained_in_network',
'cloudify.gcp.relationships.instance_contained_in_network'],
filter_resource_types=[
'cloudify.nodes.gcp.Network',
'cloudify.nodes.gcp.SubNetwork',
Expand Down
11 changes: 7 additions & 4 deletions cloudify_gcp/compute/subnetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@ def create(name, region, subnet, **kwargs):
name = utils.get_final_resource_name(name)
network = utils.get_relationships(
ctx,
filter_relationships='cloudify.gcp.relationships'
'.contained_in_network'
filter_relationships=[
'cloudify.relationships.gcp.contained_in_network',
'cloudify.gcp.relationships.contained_in_network']
)[0].target.instance

subnetwork = SubNetwork(
Expand Down Expand Up @@ -174,12 +175,14 @@ def creation_validation(**kwargs):
if not ctx.node.properties['region']:
raise NonRecoverableError("region must be supplied")

rel_type = 'cloudify.gcp.relationships.contained_in_network'
rel_type = 'cloudify.relationships.gcp.contained_in_network'
node_type = 'cloudify.nodes.gcp.Network'

rels = utils.get_relationships(
ctx,
filter_relationships=[rel_type])
filter_relationships=[
'cloudify.relationships.gcp.contained_in_network',
'cloudify.gcp.relationships.contained_in_network'])

if len(rels) != 1:
raise NonRecoverableError(
Expand Down
10 changes: 5 additions & 5 deletions cloudify_gcp/compute/tests/test_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ def patch_zones():
@patch('cloudify_gcp.gcp.build')
@pytest.mark.parametrize(
'region, node_type, section', [
('region', 'cloudify.gcp.nodes.Address', 'addresses'),
(None, 'cloudify.gcp.nodes.Address', 'addresses'),
(None, 'cloudify.gcp.nodes.GlobalAddress', 'globalAddresses'),
('region', 'cloudify.nodes.gcp.Address', 'addresses'),
(None, 'cloudify.nodes.gcp.Address', 'addresses'),
(None, 'cloudify.nodes.gcp.GlobalAddress', 'globalAddresses'),
],
)
def test_create(mock_build, region, node_type, section, ctx):
Expand Down Expand Up @@ -68,8 +68,8 @@ def test_create(mock_build, region, node_type, section, ctx):
@patch('cloudify_gcp.gcp.build')
@pytest.mark.parametrize(
'node_type, section', [
('cloudify.gcp.nodes.Address', 'addresses'),
('cloudify.gcp.nodes.GlobalAddress', 'globalAddresses'),
('cloudify.nodes.gcp.Address', 'addresses'),
('cloudify.nodes.gcp.GlobalAddress', 'globalAddresses'),
],
)
def test_delete(mock_build, node_type, section, ctx):
Expand Down
2 changes: 1 addition & 1 deletion cloudify_gcp/compute/tests/test_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ def test_delete_deleted(self, mock_is_deleted, mock_build, *args):
@patch('cloudify_gcp.utils.get_item_from_gcp_response', return_value={
'networkInterfaces': [{'accessConfigs': [{'natIP': '🕷'}]}]})
def test_add_external_ip(self, mock_getitem, mock_build, *args):
self.ctxmock.target.node.type = 'cloudify.gcp.nodes.Address'
self.ctxmock.target.node.type = 'cloudify.nodes.gcp.Address'
self.ctxmock.target.node.properties = {
'use_external_resource': False,
}
Expand Down
10 changes: 5 additions & 5 deletions cloudify_gcp/compute/tests/test_subnetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def setUp(self):

def test_create(self, mock_build, *args):
rel = Mock()
rel.type = 'cloudify.gcp.relationships.contained_in_network'
rel.target.node.type = 'cloudify.gcp.nodes.Network'
rel.type = 'cloudify.relationships.gcp.contained_in_network'
rel.target.node.type = 'cloudify.nodes.gcp.Network'
rel.target.node.properties = {
'auto_subnets': False,
}
Expand Down Expand Up @@ -71,13 +71,13 @@ def test_create_validation(self, mock_build, *args):
with self.assertRaises(NonRecoverableError) as e:
subnetwork.creation_validation()
self.assertIn(
'cloudify.gcp.relationships.contained_in_network',
'cloudify.relationships.gcp.contained_in_network',
str(e.exception))

def test_create_auto_validate(self, mock_build, *args):
rel = Mock()
rel.type = 'cloudify.gcp.relationships.contained_in_network'
rel.target.node.type = 'cloudify.gcp.nodes.Network'
rel.type = 'cloudify.relationships.gcp.contained_in_network'
rel.target.node.type = 'cloudify.nodes.gcp.Network'
rel.target.node.properties = {
'auto_subnets': True,
}
Expand Down
20 changes: 15 additions & 5 deletions cloudify_gcp/dns/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,23 @@ def creation_validation(*args, **kwargs):
rel_types = [rel.type for rel in rels]

if (
'cloudify.relationships.gcp.'
'dns_record_contained_in_zone') not in rel_types or (
'cloudify.gcp.relationships.'
'dns_record_contained_in_zone') not in rel_types:
'dns_record_contained_in_zone'
) not in rel_types:
raise NonRecoverableError('record must be contained in a zone')

for rel in utils.get_relationships(
rels,
filter_relationships=[
'cloudify.relationships.gcp.dns_record_connected_to_instance',
'cloudify.gcp.relationships.dns_record_connected_to_instance']
):
instance_rels = utils.get_relationships(
rel.target.instance.relationships,
filter_relationships=[
'cloudify.relationships.gcp.instance_connected_to_ip',
'cloudify.gcp.relationships.instance_connected_to_ip',
],
)
Expand Down Expand Up @@ -104,8 +109,9 @@ def create(type, name, resources, ttl, **kwargs):

zone = utils.get_relationships(
ctx,
filter_relationships='cloudify.gcp.relationships.'
'dns_record_contained_in_zone',
filter_relationships=[
'cloudify.relationships.gcp.dns_record_contained_in_zone',
'cloudify.gcp.relationships.dns_record_contained_in_zone'],
)[0].target.instance

dns_zone = DNSZone(
Expand All @@ -129,7 +135,9 @@ def create(type, name, resources, ttl, **kwargs):
rels = utils.get_relationships(
ctx,
filter_relationships=[
'cloudify.relationships.gcp.dns_record_connected_to_instance',
'cloudify.gcp.relationships.dns_record_connected_to_instance',
'cloudify.relationships.gcp.dns_record_connected_to_ip',
'cloudify.gcp.relationships.dns_record_connected_to_ip'
],
)
Expand Down Expand Up @@ -165,8 +173,10 @@ def delete(**_):

zone = utils.get_relationships(
ctx,
filter_relationships='cloudify.gcp.relationships.'
'dns_record_contained_in_zone',
filter_relationships=[
'cloudify.relationships.gcp.dns_record_contained_in_zone',
'cloudify.gcp.relationships.dns_record_contained_in_zone'
],
)[0].target.instance
dns_zone = DNSZone(
gcp_config,
Expand Down
6 changes: 3 additions & 3 deletions cloudify_gcp/dns/tests/test_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def setUp(self):
super(TestGCPRecord, self).setUp()

rel = Mock()
rel.type = 'cloudify.gcp.relationships.dns_record_contained_in_zone'
rel.type = 'cloudify.relationships.gcp.dns_record_contained_in_zone'
rel.target.instance.runtime_properties = {
'kind': 'dns#managedZone',
'name': 'target instance',
Expand Down Expand Up @@ -74,7 +74,7 @@ def test_create_with_instance(self, mock_build, *args):
]

rel = Mock()
rel.type = ('cloudify.gcp.relationships.'
rel.type = ('cloudify.relationships.gcp.'
'dns_record_connected_to_instance')
rel.target.instance.runtime_properties = {
'kind': 'compute#instance',
Expand All @@ -86,7 +86,7 @@ def test_create_with_instance(self, mock_build, *args):
# be connected to an external IP, so we need to mock its relationships
# too
rel_rel = Mock()
rel_rel.type = 'cloudify.gcp.relationships.instance_connected_to_ip'
rel_rel.type = 'cloudify.relationships.gcp.instance_connected_to_ip'
rel.target.instance.relationships = [rel_rel]
self.ctxmock.instance.relationships.append(rel)

Expand Down
2 changes: 1 addition & 1 deletion cloudify_gcp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ def get_net_and_subnet(ctx):
else:
raise NonRecoverableError(
'Unsupported target type for '
"'cloudify.gcp.relationships.instance_contained_in_network")
"'cloudify.relationships.gcp.instance_contained_in_network")
else:
config = get_gcp_config()
network = config['network']
Expand Down
12 changes: 6 additions & 6 deletions manager_tests/test_gcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

CFY_GCP_COMPUTE_RESOURCE = {
'nodecellar.nodes.MonitoredServer': 'instances',
'cloudify.gcp.nodes.Instance': 'instances',
'cloudify.gcp.nodes.FirewallRule': 'firewall-rules',
'cloudify.gcp.nodes.SubNetwork': 'networks subnets',
'cloudify.gcp.nodes.Network': 'networks',
'cloudify.nodes.gcp.Instance': 'instances',
'cloudify.nodes.gcp.FirewallRule': 'firewall-rules',
'cloudify.nodes.gcp.SubNetwork': 'networks subnets',
'cloudify.nodes.gcp.Network': 'networks',
}

CFY_NODES_PATTERNS = ['cloudify.gcp.nodes', 'nodecellar.nodes']
CFY_NODES_PATTERNS = ['cloudify.nodes.gcp', 'nodecellar.nodes']

DIAMOND_WAGON = 'https://github.com/cloudify-cosmo/' \
'cloudify-diamond-plugin/releases/' \
Expand All @@ -30,7 +30,7 @@ class TestGCP(EcosystemTestBase):

@property
def node_type_prefix(self):
return 'cloudify.gcp.nodes'
return 'cloudify.nodes.gcp'

@property
def plugin_mapping(self):
Expand Down
2 changes: 1 addition & 1 deletion plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins:
gcp_plugin:
executor: central_deployment_agent
package_name: cloudify-gcp-plugin
package_version: 1.9.2
package_version: 1.9.3
dsl_definitions:
use_external_resource_desc: >
Indicate whether the resource exists or if Cloudify should create the resource, true if you are bringing an existing resource, false if you want cloudify to create it.
Expand Down
2 changes: 1 addition & 1 deletion plugin_1_4.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins:
gcp_plugin:
executor: central_deployment_agent
package_name: cloudify-gcp-plugin
package_version: 1.9.2
package_version: 1.9.3
dsl_definitions:
use_external_resource_desc: >
Indicate whether the resource exists or if Cloudify should create the resource, true if you are bringing an existing resource, false if you want cloudify to create it.
Expand Down
2 changes: 1 addition & 1 deletion plugin_1_5.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins:
gcp_plugin:
executor: central_deployment_agent
package_name: cloudify-gcp-plugin
package_version: 1.9.2
package_version: 1.9.3
properties_description: Manage Azure resources.
properties:
auth:
Expand Down
2 changes: 1 addition & 1 deletion v2_plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins:
gcp_plugin:
executor: central_deployment_agent
package_name: cloudify-gcp-plugin
package_version: 1.9.2
package_version: 1.9.3
dsl_definitions:
use_external_resource_desc: >
Indicate whether the resource exists or if Cloudify should create the resource, true if you are bringing an existing resource, false if you want cloudify to create it.
Expand Down

0 comments on commit dee47f5

Please sign in to comment.