From ab3413a15aeb3b3669da94fa383ec07212eeb915 Mon Sep 17 00:00:00 2001 From: "jose.lausuch" Date: Tue, 2 Feb 2016 17:49:57 +0100 Subject: Create security groups with ICMP and SSH rules for vPing tests JIRA: FUNCTEST-133 Some installers don't allow icmp and TCP port 22 (SSH) in the default security group. To avoid any dependency with the installer, vPing will create its own security group with those rules and delete it afterwards. Change-Id: I6f31f21c240d80eed8bead638af51aa7e1e92aad Signed-off-by: jose.lausuch --- testcases/functest_utils.py | 53 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'testcases/functest_utils.py') diff --git a/testcases/functest_utils.py b/testcases/functest_utils.py index debdc38f..57ec1863 100644 --- a/testcases/functest_utils.py +++ b/testcases/functest_utils.py @@ -423,6 +423,58 @@ def get_security_groups(neutron_client): return None +def create_security_group(neutron_client, sg_name, sg_description): + json_body= {'security_group' : { 'name' : sg_name, \ + 'description' : sg_description }} + try: + secgroup = neutron_client.create_security_group(json_body) + return secgroup['security_group'] + except Exception, e: + print "Error [create_security_group(neutron_client, '%s', '%s')]:" % \ + (sg_name,sg_description), e + return False + + +def create_secgroup_rule(neutron_client, sg_id, direction, protocol, + port_range_min = None, port_range_max = None): + if port_range_min == None and port_range_max == None: + json_body = { 'security_group_rule' : \ + { 'direction' : direction, \ + 'security_group_id' : sg_id, \ + 'protocol' : protocol } } + elif port_range_min != None and port_range_max != None: + json_body = { 'security_group_rule' : \ + { 'direction' : direction, \ + 'security_group_id' : sg_id, \ + 'port_range_min': port_range_min, \ + 'port_range_max' : port_range_max, \ + 'protocol' : protocol } } + else: + print "Error [create_secgroup_rule(neutron_client, '%s', '%s', "\ + "'%s', '%s', '%s', '%s')]:" %(neutron_client, sg_id, direction, \ + port_range_min, port_range_max, protocol),\ + " Invalid values for port_range_min, port_range_max" + return False + try: + neutron_client.create_security_group_rule(json_body) + return True + except Exception, e: + print "Error [create_secgroup_rule(neutron_client, '%s', '%s', "\ + "'%s', '%s', '%s', '%s')]:" %(neutron_client, sg_id, direction, \ + port_range_min, port_range_max, protocol), e + return False + + +def add_secgroup_to_instance(nova_client, instance_id, secgroup_id): + try: + nova_client.servers.add_security_group(instance_id, secgroup_id) + return True + except Exception, e: + print "Error [add_secgroup_to_instance(nova_client, '%s', '%s')]: " % \ + (instance_id, secgroup_id), e + return False + + def update_sg_quota(neutron_client, tenant_id, sg_quota, sg_rule_quota): json_body = {"quota": { "security_group": sg_quota, @@ -449,6 +501,7 @@ def delete_security_group(neutron_client, secgroup_id): + #********************************************* # GLANCE #********************************************* -- cgit 1.2.3-korg