aboutsummaryrefslogtreecommitdiffstats
path: root/testcases/functest_utils.py
diff options
context:
space:
mode:
authorjose.lausuch <jose.lausuch@ericsson.com>2016-02-02 17:49:57 +0100
committerjose.lausuch <jose.lausuch@ericsson.com>2016-02-02 18:05:52 +0100
commitab3413a15aeb3b3669da94fa383ec07212eeb915 (patch)
tree3b7c56e2b43be1e4159320c36455332d5a4b5d88 /testcases/functest_utils.py
parent5bb53025a593bbda834ef6ad325faba5aa073f7f (diff)
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 <jose.lausuch@ericsson.com>
Diffstat (limited to 'testcases/functest_utils.py')
-rw-r--r--testcases/functest_utils.py53
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
#*********************************************