diff options
author | jose.lausuch <jose.lausuch@ericsson.com> | 2016-02-02 17:27:05 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@172.30.200.206> | 2016-02-02 17:27:05 +0000 |
commit | 3630ec141c8ef230388735499bf9a57c775db3d0 (patch) | |
tree | 140ccd328dada5dcf570913c7250034356174a59 /testcases/functest_utils.py | |
parent | 86c95df05ef125218f392748a177d2f9aa79848f (diff) | |
parent | ab3413a15aeb3b3669da94fa383ec07212eeb915 (diff) |
Merge "Create security groups with ICMP and SSH rules for vPing tests"
Diffstat (limited to 'testcases/functest_utils.py')
-rw-r--r-- | testcases/functest_utils.py | 53 |
1 files changed, 53 insertions, 0 deletions
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 #********************************************* |