CLOUDSTACK-4691: move egress rules host maintenance tests to maint folder

Signed-off-by: venkataswamybabu budumuru <venkataswamybabu.budumuru@citrix.com>
(cherry picked from commit 6b28e03d6d88e9b6bd9d0521a45c93d5b4af6501)
This commit is contained in:
SrikanteswaraRao Talluri 2013-09-25 15:16:13 +05:30 committed by venkataswamybabu budumuru
parent ff2bd3d443
commit 65da24c35e
5 changed files with 307 additions and 17 deletions

View File

@ -0,0 +1,290 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
""" P1 for Egresss & Ingress rules
"""
#Import Local Modules
import marvin
from nose.plugins.attrib import attr
from marvin.cloudstackTestCase import *
from marvin.cloudstackAPI import *
from marvin.remoteSSHClient import remoteSSHClient
from marvin.integration.lib.utils import *
from marvin.integration.lib.base import *
from marvin.integration.lib.common import *
#Import System modules
import time
import subprocess
class Services:
"""Test Security groups Services
"""
def __init__(self):
self.services = {
"account": {
"email": "test@test.com",
"firstname": "Test",
"lastname": "User",
"username": "test",
# Random characters are appended in create account to
# ensure unique username generated each time
"password": "password",
},
"virtual_machine": {
# Create a small virtual machine instance with disk offering
"displayname": "Test VM",
"username": "root", # VM creds for SSH
"password": "password",
"ssh_port": 22,
"hypervisor": 'XenServer',
"privateport": 22,
"publicport": 22,
"protocol": 'TCP',
"userdata": 'This is sample data',
},
"service_offering": {
"name": "Tiny Instance",
"displaytext": "Tiny Instance",
"cpunumber": 1,
"cpuspeed": 100, # in MHz
"memory": 128, # In MBs
},
"security_group": {
"name": 'SSH',
"protocol": 'TCP',
"startport": 22,
"endport": 22,
"cidrlist": '0.0.0.0/0',
},
"ostype": 'CentOS 5.3 (64-bit)',
# CentOS 5.3 (64-bit)
"sleep": 60,
"timeout": 10,
}
class TestEgressAfterHostMaintenance(cloudstackTestCase):
def setUp(self):
self.apiclient = self.testClient.getApiClient()
self.dbclient = self.testClient.getDbConnection()
self.cleanup = []
return
def tearDown(self):
try:
#Clean up, terminate the created templates
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@classmethod
def setUpClass(cls):
cls.services = Services().services
cls.api_client = super(
TestEgressAfterHostMaintenance,
cls
).getClsTestClient().getApiClient()
# Get Zone, Domain and templates
cls.domain = get_domain(cls.api_client, cls.services)
cls.zone = get_zone(cls.api_client, cls.services)
cls.services['mode'] = cls.zone.networktype
cls.pod = get_pod(
cls.api_client,
zoneid=cls.zone.id
)
template = get_template(
cls.api_client,
cls.zone.id,
cls.services["ostype"]
)
cls.services["domainid"] = cls.domain.id
cls.services["virtual_machine"]["zoneid"] = cls.zone.id
cls.services["virtual_machine"]["template"] = template.id
cls.service_offering = ServiceOffering.create(
cls.api_client,
cls.services["service_offering"]
)
cls.account = Account.create(
cls.api_client,
cls.services["account"],
domainid=cls.domain.id
)
cls.services["account"] = cls.account.name
cls._cleanup = [
cls.account,
cls.service_offering
]
return
@classmethod
def tearDownClass(cls):
try:
#Cleanup resources used
cleanup_resources(cls.api_client, cls._cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@attr(speed = "slow")
@attr(tags = ["sg", "eip", "maintenance"])
def test_egress_after_host_maintenance(self):
"""Test maintenance case for egress
"""
# Validate the following:
# 1. createaccount of type user
# 2. createsecuritygroup (ssh) for this account
# 3. authorizeSecurityGroupIngress to allow ssh access to the VM
# 4. authorizeSecurityGroupEgress to allow ssh access only out to
# CIDR: 0.0.0.0/0
# 5. deployVirtualMachine into this security group (ssh)
# 6. deployed VM should be Running, ssh should be allowed into the VM
# 7. Enable maintenance mode for host, cance maintenance mode
# 8. User should be able to SSH into VM after maintainace
security_group = SecurityGroup.create(
self.apiclient,
self.services["security_group"],
account=self.account.name,
domainid=self.account.domainid
)
self.debug("Created security group with ID: %s" % security_group.id)
# Default Security group should not have any ingress rule
sercurity_groups = SecurityGroup.list(
self.apiclient,
account=self.account.name,
domainid=self.account.domainid
)
self.assertEqual(
isinstance(sercurity_groups, list),
True,
"Check for list security groups response"
)
self.assertEqual(
len(sercurity_groups),
2,
"Check List Security groups response"
)
# Authorize Security group to SSH to VM
self.debug(
"Authorizing ingress rule for sec group ID: %s for ssh access"
% security_group.id)
ingress_rule = security_group.authorize(
self.apiclient,
self.services["security_group"],
account=self.account.name,
domainid=self.account.domainid
)
self.assertEqual(
isinstance(ingress_rule, dict),
True,
"Check ingress rule created properly"
)
ssh_rule = (ingress_rule["ingressrule"][0]).__dict__
# Authorize Security group to SSH to VM
self.debug(
"Authorizing egress rule for sec group ID: %s for ssh access"
% security_group.id)
egress_rule = security_group.authorizeEgress(
self.apiclient,
self.services["security_group"],
account=self.account.name,
domainid=self.account.domainid
)
self.assertEqual(
isinstance(egress_rule, dict),
True,
"Check egress rule created properly"
)
ssh_egress_rule = (egress_rule["egressrule"][0]).__dict__
self.virtual_machine = VirtualMachine.create(
self.apiclient,
self.services["virtual_machine"],
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
securitygroupids=[security_group.id]
)
self.debug("Deploying VM in account: %s" % self.account.name)
# Should be able to SSH VM
try:
self.debug("SSH into VM: %s" % self.virtual_machine.id)
ssh = self.virtual_machine.get_ssh_client()
except Exception as e:
self.fail("SSH Access failed for %s: %s" % \
(self.virtual_machine.ipaddress, e)
)
vms = VirtualMachine.list(
self.apiclient,
id=self.virtual_machine.id,
listall=True
)
self.assertEqual(
isinstance(vms, list),
True,
"Check list VMs response for valid host"
)
vm = vms[0]
self.debug("Enabling host maintenance for ID: %s" % vm.hostid)
cmd = prepareHostForMaintenance.prepareHostForMaintenanceCmd()
cmd.id = vm.hostid
self.apiclient.prepareHostForMaintenance(cmd)
self.debug("Canceling host maintenance for ID: %s" % vm.hostid)
cmd = cancelHostMaintenance.cancelHostMaintenanceCmd()
cmd.id = vm.hostid
self.apiclient.cancelHostMaintenance(cmd)
self.debug("Waiting for SSVMs to come up")
wait_for_ssvms(
self.apiclient,
zoneid=self.zone.id,
podid=self.pod.id,
)
self.debug("Starting VM: %s" % self.virtual_machine.id)
self.virtual_machine.start(self.apiclient)
# Should be able to SSH VM
try:
self.debug("SSH into VM: %s" % self.virtual_machine.id)
ssh = self.virtual_machine.get_ssh_client(reconnect=True)
except Exception as e:
self.fail("SSH Access failed for %s: %s" % \
(self.virtual_machine.ipaddress, e)
)
return

View File

@ -616,7 +616,7 @@ class TestHostHighAvailability(cloudstackTestCase):
"The virtual machine is not ha enabled so check if VM is created on host which is also not ha enabled" "The virtual machine is not ha enabled so check if VM is created on host which is also not ha enabled"
) )
#put the Host in maintainance mode #put the Host in maintenance mode
self.debug("Enabling maintenance mode for host %s" % vm_with_ha_enabled.hostid) self.debug("Enabling maintenance mode for host %s" % vm_with_ha_enabled.hostid)
cmd = prepareHostForMaintenance.prepareHostForMaintenanceCmd() cmd = prepareHostForMaintenance.prepareHostForMaintenanceCmd()
cmd.id = vm_with_ha_enabled.hostid cmd.id = vm_with_ha_enabled.hostid
@ -748,7 +748,7 @@ class TestHostHighAvailability(cloudstackTestCase):
"The virtual machine is not ha enabled so check if VM is created on host which is also not ha enabled" "The virtual machine is not ha enabled so check if VM is created on host which is also not ha enabled"
) )
#put the Host in maintainance mode #put the Host in maintenance mode
self.debug("Enabling maintenance mode for host %s" % vm_with_ha_disabled.hostid) self.debug("Enabling maintenance mode for host %s" % vm_with_ha_disabled.hostid)
cmd = prepareHostForMaintenance.prepareHostForMaintenanceCmd() cmd = prepareHostForMaintenance.prepareHostForMaintenanceCmd()
cmd.id = vm_with_ha_disabled.hostid cmd.id = vm_with_ha_disabled.hostid

View File

@ -2149,7 +2149,7 @@ class TestInvalidParametersForEgress(cloudstackTestCase):
return return
class TestEgressAfterHostMaintainance(cloudstackTestCase): class TestEgressAfterHostMaintenance(cloudstackTestCase):
def setUp(self): def setUp(self):
@ -2171,7 +2171,7 @@ class TestEgressAfterHostMaintainance(cloudstackTestCase):
def setUpClass(cls): def setUpClass(cls):
cls.services = Services().services cls.services = Services().services
cls.api_client = super( cls.api_client = super(
TestEgressAfterHostMaintainance, TestEgressAfterHostMaintenance,
cls cls
).getClsTestClient().getApiClient() ).getClsTestClient().getApiClient()
@ -2222,7 +2222,7 @@ class TestEgressAfterHostMaintainance(cloudstackTestCase):
@attr(speed = "slow") @attr(speed = "slow")
@attr(tags = ["sg", "eip", "maintenance"]) @attr(tags = ["sg", "eip", "maintenance"])
def test_egress_after_host_maintainance(self): def test_egress_after_host_maintenance(self):
"""Test maintenance case for egress """Test maintenance case for egress
""" """
@ -2234,7 +2234,7 @@ class TestEgressAfterHostMaintainance(cloudstackTestCase):
# CIDR: 0.0.0.0/0 # CIDR: 0.0.0.0/0
# 5. deployVirtualMachine into this security group (ssh) # 5. deployVirtualMachine into this security group (ssh)
# 6. deployed VM should be Running, ssh should be allowed into the VM # 6. deployed VM should be Running, ssh should be allowed into the VM
# 7. Enable maintainance mode for host, cance maintainance mode # 7. Enable maintenance mode for host, cance maintenance mode
# 8. User should be able to SSH into VM after maintainace # 8. User should be able to SSH into VM after maintainace
security_group = SecurityGroup.create( security_group = SecurityGroup.create(
@ -2329,12 +2329,12 @@ class TestEgressAfterHostMaintainance(cloudstackTestCase):
) )
vm = vms[0] vm = vms[0]
self.debug("Enabling host maintainance for ID: %s" % vm.hostid) self.debug("Enabling host maintenance for ID: %s" % vm.hostid)
cmd = prepareHostForMaintenance.prepareHostForMaintenanceCmd() cmd = prepareHostForMaintenance.prepareHostForMaintenanceCmd()
cmd.id = vm.hostid cmd.id = vm.hostid
self.apiclient.prepareHostForMaintenance(cmd) self.apiclient.prepareHostForMaintenance(cmd)
self.debug("Canceling host maintainance for ID: %s" % vm.hostid) self.debug("Canceling host maintenance for ID: %s" % vm.hostid)
cmd = cancelHostMaintenance.cancelHostMaintenanceCmd() cmd = cancelHostMaintenance.cancelHostMaintenanceCmd()
cmd.id = vm.hostid cmd.id = vm.hostid
self.apiclient.cancelHostMaintenance(cmd) self.apiclient.cancelHostMaintenance(cmd)

View File

@ -1803,7 +1803,7 @@ class Host:
return return
def enableMaintenance(self, apiclient): def enableMaintenance(self, apiclient):
"""enables maintainance mode Host""" """enables maintenance mode Host"""
cmd = prepareHostForMaintenance.prepareHostForMaintenanceCmd() cmd = prepareHostForMaintenance.prepareHostForMaintenanceCmd()
cmd.id = self.id cmd.id = self.id
@ -1811,14 +1811,14 @@ class Host:
@classmethod @classmethod
def enableMaintenance(cls, apiclient, id): def enableMaintenance(cls, apiclient, id):
"""enables maintainance mode Host""" """enables maintenance mode Host"""
cmd = prepareHostForMaintenance.prepareHostForMaintenanceCmd() cmd = prepareHostForMaintenance.prepareHostForMaintenanceCmd()
cmd.id = id cmd.id = id
return apiclient.prepareHostForMaintenance(cmd) return apiclient.prepareHostForMaintenance(cmd)
def cancelMaintenance(self, apiclient): def cancelMaintenance(self, apiclient):
"""Cancels maintainance mode Host""" """Cancels maintenance mode Host"""
cmd = cancelHostMaintenance.cancelHostMaintenanceCmd() cmd = cancelHostMaintenance.cancelHostMaintenanceCmd()
cmd.id = self.id cmd.id = self.id
@ -1826,7 +1826,7 @@ class Host:
@classmethod @classmethod
def cancelMaintenance(cls, apiclient, id): def cancelMaintenance(cls, apiclient, id):
"""Cancels maintainance mode Host""" """Cancels maintenance mode Host"""
cmd = cancelHostMaintenance.cancelHostMaintenanceCmd() cmd = cancelHostMaintenance.cancelHostMaintenanceCmd()
cmd.id = id cmd.id = id
@ -1895,7 +1895,7 @@ class StoragePool:
return return
def enableMaintenance(self, apiclient): def enableMaintenance(self, apiclient):
"""enables maintainance mode Storage pool""" """enables maintenance mode Storage pool"""
cmd = enableStorageMaintenance.enableStorageMaintenanceCmd() cmd = enableStorageMaintenance.enableStorageMaintenanceCmd()
cmd.id = self.id cmd.id = self.id

View File

@ -1053,8 +1053,8 @@ class Host:
return return
def enableMaintenance(self, apiclient): def enableMaintenance(self, apiclient):
"""enables maintainance mode Host""" """enables maintenance mode Host"""
cmd = prepareHostForMaintenance.prepareHostForMaintenanceCmd() cmd = prepareHostForMaintenance.prepareHostForMaintenanceCmd()
cmd.id = self.id cmd.id = self.id
return apiclient.prepareHostForMaintenance(cmd) return apiclient.prepareHostForMaintenance(cmd)
@ -1113,8 +1113,8 @@ class StoragePool:
return return
def enableMaintenance(self, apiclient): def enableMaintenance(self, apiclient):
"""enables maintainance mode Storage pool""" """enables maintenance mode Storage pool"""
cmd = enableStorageMaintenance.enableStorageMaintenanceCmd() cmd = enableStorageMaintenance.enableStorageMaintenanceCmd()
cmd.id = self.id cmd.id = self.id
return apiclient.enableStorageMaintenance(cmd) return apiclient.enableStorageMaintenance(cmd)