Skip to content

Commit

Permalink
Merge pull request #1354 from grycap/devel
Browse files Browse the repository at this point in the history
Fix 1338
  • Loading branch information
micafer authored Mar 28, 2022
2 parents 52b7efd + bb24749 commit 6f1b4f2
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 19 deletions.
2 changes: 1 addition & 1 deletion IM/connectors/Azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def create_nsg(self, location, group_name, nsg_name, outports, network_client, i
outport.get_port_end())
sr['destination_port_range'] = "%d-%d" % (outport.get_port_init(), outport.get_port_end())
security_rules.append(sr)
elif outport.get_local_port() != 22:
else:
sr['name'] = 'sr-%s-%d-%d' % (outport.get_protocol(),
outport.get_remote_port(),
outport.get_local_port())
Expand Down
21 changes: 11 additions & 10 deletions IM/connectors/OpenStack.py
Original file line number Diff line number Diff line change
Expand Up @@ -1543,17 +1543,18 @@ def create_security_groups(self, driver, inf, radl):
outport.get_remote_cidr())
except Exception as ex:
self.log_warn("Exception adding SG rules: %s" % get_ex_error(ex))
self.error_messages += ("Exception adding port range: %s-%s to SG rules.\n" %
outport.get_port_init(), outport.get_port_end())
else:
if outport.get_remote_port() != 22 or not network.isPublic():
try:
driver.ex_create_security_group_rule(sg, outport.get_protocol(),
outport.get_remote_port(),
outport.get_remote_port(),
outport.get_remote_cidr())
except Exception as ex:
self.log_warn("Exception adding SG rules: %s" % get_ex_error(ex))
self.error_messages += ("Exception adding port %s to SG rules.\n" %
outport.get_remote_port())
try:
driver.ex_create_security_group_rule(sg, outport.get_protocol(),
outport.get_remote_port(),
outport.get_remote_port(),
outport.get_remote_cidr())
except Exception as ex:
self.log_warn("Exception adding SG rules: %s" % get_ex_error(ex))
self.error_messages += ("Exception adding port %s to SG rules.\n" %
outport.get_remote_port())

return res

Expand Down
11 changes: 4 additions & 7 deletions IM/tosca/Tosca.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,11 @@ def _format_outports(ports_dict):
for port in ports_dict.values():
protocol = "tcp"
source_range = None
remote_cidr = None
remote_cidr = ""
if "protocol" in port:
protocol = port["protocol"]
if "remote_cidr" in port:
remote_cidr = port["remote_cidr"]
remote_cidr = "%s-" % port["remote_cidr"]
if "source_range" in port:
source_range = port["source_range"]
else:
Expand All @@ -368,14 +368,11 @@ def _format_outports(ports_dict):
if source_range:
if res:
res += ","
res += "%s:%s/%s" % (source_range[0], source_range[1], protocol)
res += "%s%s:%s/%s" % (remote_cidr, source_range[0], source_range[1], protocol)
else:
if res:
res += ","
res += "%s/%s-%s/%s" % (remote_port, protocol, local_port, protocol)

if remote_cidr:
res = "%s-%s" % (remote_cidr, res)
res += "%s%s/%s-%s/%s" % (remote_cidr, remote_port, protocol, local_port, protocol)

return res

Expand Down
5 changes: 5 additions & 0 deletions test/files/tosca_long.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ topology_template:
http_port:
protocol: tcp
source: 10000
remote_cidr: 0.0.0.0/0
other_port:
protocol: tcp
source: 80
remote_cidr: 8.0.0.0/24
scalable:
properties:
count: 1
Expand Down
3 changes: 2 additions & 1 deletion test/unit/Tosca.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ def test_tosca_to_radl(self):
self.assertIn('80/tcp-80/tcp', net1.getValue("outports"))
self.assertIn('8080/tcp-8080/tcp', net1.getValue("outports"))

self.assertIn('10000/tcp-10000/tcp', net2.getValue("outports"))
self.assertIn('0.0.0.0/0-10000/tcp-10000/tcp', net2.getValue("outports"))
self.assertIn('8.0.0.0/24-80/tcp-80/tcp', net2.getValue("outports"))

lrms_wn = radl.get_system_by_name('lrms_wn')
self.assertEqual(lrms_wn.getValue('memory.size'), 2000000000)
Expand Down
1 change: 1 addition & 0 deletions test/unit/connectors/OpenStack.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ def test_20_launch(self, get_image_data, save_data, get_driver):
]
self.assertEqual(driver.create_node.call_args_list[0][1]['ex_blockdevicemappings'], mappings)
self.assertEqual(driver.ex_create_subnet.call_args_list[0][0][2], "10.0.1.0/24")
self.assertEqual(driver.ex_create_security_group_rule.call_args_list[8][0][1:], ('tcp', 22, 22, '0.0.0.0/0'))

# test with proxy auth data
auth = Authentication([{'id': 'ost', 'type': 'OpenStack', 'proxy': 'proxy',
Expand Down

0 comments on commit 6f1b4f2

Please sign in to comment.