mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Minor tagging and comments in tests
Adding tags to the deployvm test from the marvin tutorial Adding docstrings to the vm snapshot tests Add tag to the pvlan test Signed-off-by: Prasanna Santhanam <tsp@apache.org>
This commit is contained in:
parent
a67728b312
commit
698da2a279
@ -31,6 +31,8 @@ from marvin.integration.lib.utils import cleanup_resources
|
|||||||
#common - commonly used methods for all tests are listed here
|
#common - commonly used methods for all tests are listed here
|
||||||
from marvin.integration.lib.common import get_zone, get_domain, get_template
|
from marvin.integration.lib.common import get_zone, get_domain, get_template
|
||||||
|
|
||||||
|
from nose.plugins.attrib import attr
|
||||||
|
|
||||||
class TestData(object):
|
class TestData(object):
|
||||||
"""Test data object that is required to create resources
|
"""Test data object that is required to create resources
|
||||||
"""
|
"""
|
||||||
@ -94,6 +96,7 @@ class TestDeployVM(cloudstackTestCase):
|
|||||||
self.account
|
self.account
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@attr(tags = ['advanced', 'simulator', 'basic', 'sg'])
|
||||||
def test_deploy_vm(self):
|
def test_deploy_vm(self):
|
||||||
"""Test Deploy Virtual Machine
|
"""Test Deploy Virtual Machine
|
||||||
|
|
||||||
|
|||||||
@ -41,6 +41,7 @@ class TestPVLAN(cloudstackTestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.apiClient = self.testClient.getApiClient()
|
self.apiClient = self.testClient.getApiClient()
|
||||||
|
|
||||||
|
@attr(tags = ["advanced"])
|
||||||
def test_create_pvlan_network(self):
|
def test_create_pvlan_network(self):
|
||||||
self.debug("Test create pvlan network")
|
self.debug("Test create pvlan network")
|
||||||
createNetworkCmd = createNetwork.createNetworkCmd()
|
createNetworkCmd = createNetwork.createNetworkCmd()
|
||||||
|
|||||||
@ -1,308 +1,310 @@
|
|||||||
# Licensed to the Apache Software Foundation (ASF) under one
|
# Licensed to the Apache Software Foundation (ASF) under one
|
||||||
# or more contributor license agreements. See the NOTICE file
|
# or more contributor license agreements. See the NOTICE file
|
||||||
# distributed with this work for additional information
|
# distributed with this work for additional information
|
||||||
# regarding copyright ownership. The ASF licenses this file
|
# regarding copyright ownership. The ASF licenses this file
|
||||||
# to you under the Apache License, Version 2.0 (the
|
# to you under the Apache License, Version 2.0 (the
|
||||||
# "License"); you may not use this file except in compliance
|
# "License"); you may not use this file except in compliance
|
||||||
# with the License. You may obtain a copy of the License at
|
# with the License. You may obtain a copy of the License at
|
||||||
#
|
#
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
#
|
#
|
||||||
# Unless required by applicable law or agreed to in writing,
|
# Unless required by applicable law or agreed to in writing,
|
||||||
# software distributed under the License is distributed on an
|
# software distributed under the License is distributed on an
|
||||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
# KIND, either express or implied. See the License for the
|
# KIND, either express or implied. See the License for the
|
||||||
# specific language governing permissions and limitations
|
# specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
# Import Local Modules
|
# Import Local Modules
|
||||||
import marvin
|
import marvin
|
||||||
from nose.plugins.attrib import attr
|
from nose.plugins.attrib import attr
|
||||||
from marvin.cloudstackTestCase import *
|
from marvin.cloudstackTestCase import *
|
||||||
from marvin.cloudstackAPI import *
|
from marvin.cloudstackAPI import *
|
||||||
from marvin.integration.lib.utils import *
|
from marvin.integration.lib.utils import *
|
||||||
from marvin.integration.lib.base import *
|
from marvin.integration.lib.base import *
|
||||||
from marvin.integration.lib.common import *
|
from marvin.integration.lib.common import *
|
||||||
from marvin.remoteSSHClient import remoteSSHClient
|
|
||||||
|
class Services:
|
||||||
class Services:
|
"""Test Snapshots Services
|
||||||
"""Test Snapshots Services
|
"""
|
||||||
"""
|
|
||||||
|
def __init__(self):
|
||||||
def __init__(self):
|
self.services = {
|
||||||
self.services = {
|
"account": {
|
||||||
"account": {
|
"email": "test@test.com",
|
||||||
"email": "test@test.com",
|
"firstname": "Test",
|
||||||
"firstname": "Test",
|
"lastname": "User",
|
||||||
"lastname": "User",
|
"username": "test",
|
||||||
"username": "test",
|
# Random characters are appended for unique
|
||||||
# Random characters are appended for unique
|
# username
|
||||||
# username
|
"password": "password",
|
||||||
"password": "password",
|
},
|
||||||
},
|
"service_offering": {
|
||||||
"service_offering": {
|
"name": "Tiny Instance",
|
||||||
"name": "Tiny Instance",
|
"displaytext": "Tiny Instance",
|
||||||
"displaytext": "Tiny Instance",
|
"cpunumber": 1,
|
||||||
"cpunumber": 1,
|
"cpuspeed": 200, # in MHz
|
||||||
"cpuspeed": 200, # in MHz
|
"memory": 256, # In MBs
|
||||||
"memory": 256, # In MBs
|
},
|
||||||
},
|
"server": {
|
||||||
"server": {
|
"displayname": "TestVM",
|
||||||
"displayname": "TestVM",
|
"username": "root",
|
||||||
"username": "root",
|
"password": "password",
|
||||||
"password": "password",
|
"ssh_port": 22,
|
||||||
"ssh_port": 22,
|
"hypervisor": 'XenServer',
|
||||||
"hypervisor": 'XenServer',
|
"privateport": 22,
|
||||||
"privateport": 22,
|
"publicport": 22,
|
||||||
"publicport": 22,
|
"protocol": 'TCP',
|
||||||
"protocol": 'TCP',
|
},
|
||||||
},
|
"mgmt_server": {
|
||||||
"mgmt_server": {
|
"ipaddress": '1.2.2.152',
|
||||||
"ipaddress": '1.2.2.152',
|
"username": "root",
|
||||||
"username": "root",
|
"password": "password",
|
||||||
"password": "password",
|
"port": 22,
|
||||||
"port": 22,
|
},
|
||||||
},
|
"templates": {
|
||||||
"templates": {
|
"displaytext": 'Template',
|
||||||
"displaytext": 'Template',
|
"name": 'Template',
|
||||||
"name": 'Template',
|
"ostype": "CentOS 5.3 (64-bit)",
|
||||||
"ostype": "CentOS 5.3 (64-bit)",
|
"templatefilter": 'self',
|
||||||
"templatefilter": 'self',
|
},
|
||||||
},
|
"test_dir": "/tmp",
|
||||||
"test_dir": "/tmp",
|
"random_data": "random.data",
|
||||||
"random_data": "random.data",
|
"snapshot_name":"TestSnapshot",
|
||||||
"snapshot_name":"TestSnapshot",
|
"snapshot_displaytext":"Test",
|
||||||
"snapshot_displaytext":"Test",
|
"ostype": "CentOS 5.3 (64-bit)",
|
||||||
"ostype": "CentOS 5.3 (64-bit)",
|
"sleep": 60,
|
||||||
"sleep": 60,
|
"timeout": 10,
|
||||||
"timeout": 10,
|
"mode": 'advanced', # Networking mode: Advanced, Basic
|
||||||
"mode": 'advanced', # Networking mode: Advanced, Basic
|
}
|
||||||
}
|
|
||||||
|
class TestVmSnapshot(cloudstackTestCase):
|
||||||
class TestVmSnapshot(cloudstackTestCase):
|
@classmethod
|
||||||
@classmethod
|
def setUpClass(cls):
|
||||||
def setUpClass(cls):
|
cls.api_client = super(TestVmSnapshot, cls).getClsTestClient().getApiClient()
|
||||||
cls.api_client = super(TestVmSnapshot, cls).getClsTestClient().getApiClient()
|
cls.services = Services().services
|
||||||
cls.services = Services().services
|
# Get Zone, Domain and templates
|
||||||
# Get Zone, Domain and templates
|
cls.domain = get_domain(cls.api_client, cls.services)
|
||||||
cls.domain = get_domain(cls.api_client, cls.services)
|
cls.zone = get_zone(cls.api_client, cls.services)
|
||||||
cls.zone = get_zone(cls.api_client, cls.services)
|
|
||||||
|
template = get_template(
|
||||||
template = get_template(
|
cls.api_client,
|
||||||
cls.api_client,
|
cls.zone.id,
|
||||||
cls.zone.id,
|
cls.services["ostype"]
|
||||||
cls.services["ostype"]
|
)
|
||||||
)
|
cls.services["domainid"] = cls.domain.id
|
||||||
cls.services["domainid"] = cls.domain.id
|
cls.services["server"]["zoneid"] = cls.zone.id
|
||||||
cls.services["server"]["zoneid"] = cls.zone.id
|
cls.services["templates"]["ostypeid"] = template.ostypeid
|
||||||
cls.services["templates"]["ostypeid"] = template.ostypeid
|
cls.services["zoneid"] = cls.zone.id
|
||||||
cls.services["zoneid"] = cls.zone.id
|
|
||||||
|
# Create VMs, NAT Rules etc
|
||||||
# Create VMs, NAT Rules etc
|
cls.account = Account.create(
|
||||||
cls.account = Account.create(
|
cls.api_client,
|
||||||
cls.api_client,
|
cls.services["account"],
|
||||||
cls.services["account"],
|
domainid=cls.domain.id
|
||||||
domainid=cls.domain.id
|
)
|
||||||
)
|
|
||||||
|
cls.services["account"] = cls.account.name
|
||||||
cls.services["account"] = cls.account.name
|
|
||||||
|
cls.service_offering = ServiceOffering.create(
|
||||||
cls.service_offering = ServiceOffering.create(
|
cls.api_client,
|
||||||
cls.api_client,
|
cls.services["service_offering"]
|
||||||
cls.services["service_offering"]
|
)
|
||||||
)
|
cls.virtual_machine = VirtualMachine.create(
|
||||||
cls.virtual_machine = VirtualMachine.create(
|
cls.api_client,
|
||||||
cls.api_client,
|
cls.services["server"],
|
||||||
cls.services["server"],
|
templateid=template.id,
|
||||||
templateid=template.id,
|
accountid=cls.account.name,
|
||||||
accountid=cls.account.name,
|
domainid=cls.account.domainid,
|
||||||
domainid=cls.account.domainid,
|
serviceofferingid=cls.service_offering.id,
|
||||||
serviceofferingid=cls.service_offering.id,
|
mode=cls.services["mode"]
|
||||||
mode=cls.services["mode"]
|
)
|
||||||
)
|
cls.random_data_0 = random_gen(100)
|
||||||
cls.random_data_0 = random_gen(100)
|
cls._cleanup = [
|
||||||
cls._cleanup = [
|
cls.service_offering,
|
||||||
cls.service_offering,
|
cls.account,
|
||||||
cls.account,
|
]
|
||||||
]
|
return
|
||||||
return
|
|
||||||
|
@classmethod
|
||||||
@classmethod
|
def tearDownClass(cls):
|
||||||
def tearDownClass(cls):
|
try:
|
||||||
try:
|
# Cleanup resources used
|
||||||
# Cleanup resources used
|
cleanup_resources(cls.api_client, cls._cleanup)
|
||||||
cleanup_resources(cls.api_client, cls._cleanup)
|
except Exception as e:
|
||||||
except Exception as e:
|
raise Exception("Warning: Exception during cleanup : %s" % e)
|
||||||
raise Exception("Warning: Exception during cleanup : %s" % e)
|
return
|
||||||
return
|
|
||||||
|
def setUp(self):
|
||||||
def setUp(self):
|
self.apiclient = self.testClient.getApiClient()
|
||||||
self.apiclient = self.testClient.getApiClient()
|
self.dbclient = self.testClient.getDbConnection()
|
||||||
self.dbclient = self.testClient.getDbConnection()
|
self.cleanup = []
|
||||||
self.cleanup = []
|
return
|
||||||
return
|
|
||||||
|
def tearDown(self):
|
||||||
def tearDown(self):
|
try:
|
||||||
try:
|
# Clean up, terminate the created instance, volumes and snapshots
|
||||||
# Clean up, terminate the created instance, volumes and snapshots
|
cleanup_resources(self.apiclient, self.cleanup)
|
||||||
cleanup_resources(self.apiclient, self.cleanup)
|
except Exception as e:
|
||||||
except Exception as e:
|
raise Exception("Warning: Exception during cleanup : %s" % e)
|
||||||
raise Exception("Warning: Exception during cleanup : %s" % e)
|
return
|
||||||
return
|
|
||||||
|
@attr(tags=["advanced", "advancedns", "smoke"])
|
||||||
@attr(tags=["advanced", "advancedns", "smoke"])
|
def test_01_create_vm_snapshots(self):
|
||||||
def test_01_create_vm_snapshots(self):
|
"""Test to create VM snapshots
|
||||||
|
"""
|
||||||
try:
|
|
||||||
# Login to VM and write data to file system
|
try:
|
||||||
ssh_client = self.virtual_machine.get_ssh_client()
|
# Login to VM and write data to file system
|
||||||
|
ssh_client = self.virtual_machine.get_ssh_client()
|
||||||
cmds = [
|
|
||||||
"echo %s > %s/%s" % (self.random_data_0, self.services["test_dir"], self.services["random_data"]),
|
cmds = [
|
||||||
"cat %s/%s" % (self.services["test_dir"], self.services["random_data"])
|
"echo %s > %s/%s" % (self.random_data_0, self.services["test_dir"], self.services["random_data"]),
|
||||||
]
|
"cat %s/%s" % (self.services["test_dir"], self.services["random_data"])
|
||||||
|
]
|
||||||
for c in cmds:
|
|
||||||
self.debug(c)
|
for c in cmds:
|
||||||
result = ssh_client.execute(c)
|
self.debug(c)
|
||||||
self.debug(result)
|
result = ssh_client.execute(c)
|
||||||
|
self.debug(result)
|
||||||
except Exception:
|
|
||||||
self.fail("SSH failed for Virtual machine: %s" %
|
except Exception:
|
||||||
self.virtual_machine.ipaddress)
|
self.fail("SSH failed for Virtual machine: %s" %
|
||||||
self.assertEqual(
|
self.virtual_machine.ipaddress)
|
||||||
self.random_data_0,
|
self.assertEqual(
|
||||||
result[0],
|
self.random_data_0,
|
||||||
"Check the random data has be write into temp file!"
|
result[0],
|
||||||
)
|
"Check the random data has be write into temp file!"
|
||||||
|
)
|
||||||
time.sleep(self.services["sleep"])
|
|
||||||
|
time.sleep(self.services["sleep"])
|
||||||
vm_snapshot = VmSnapshot.create(
|
|
||||||
self.apiclient,
|
vm_snapshot = VmSnapshot.create(
|
||||||
self.virtual_machine.id,
|
self.apiclient,
|
||||||
"false",
|
self.virtual_machine.id,
|
||||||
self.services["snapshot_name"],
|
"false",
|
||||||
self.services["snapshot_displaytext"]
|
self.services["snapshot_name"],
|
||||||
)
|
self.services["snapshot_displaytext"]
|
||||||
self.assertEqual(
|
)
|
||||||
vm_snapshot.state,
|
self.assertEqual(
|
||||||
"Ready",
|
vm_snapshot.state,
|
||||||
"Check the snapshot of vm is ready!"
|
"Ready",
|
||||||
)
|
"Check the snapshot of vm is ready!"
|
||||||
return
|
)
|
||||||
|
return
|
||||||
@attr(tags=["advanced", "advancedns", "smoke"])
|
|
||||||
def test_02_revert_vm_snapshots(self):
|
@attr(tags=["advanced", "advancedns", "smoke"])
|
||||||
try:
|
def test_02_revert_vm_snapshots(self):
|
||||||
ssh_client = self.virtual_machine.get_ssh_client()
|
"""Test to revert VM snapshots
|
||||||
|
"""
|
||||||
cmds = [
|
|
||||||
"rm -rf %s/%s" % (self.services["test_dir"], self.services["random_data"]),
|
try:
|
||||||
"ls %s/%s" % (self.services["test_dir"], self.services["random_data"])
|
ssh_client = self.virtual_machine.get_ssh_client()
|
||||||
]
|
|
||||||
|
cmds = [
|
||||||
for c in cmds:
|
"rm -rf %s/%s" % (self.services["test_dir"], self.services["random_data"]),
|
||||||
self.debug(c)
|
"ls %s/%s" % (self.services["test_dir"], self.services["random_data"])
|
||||||
result = ssh_client.execute(c)
|
]
|
||||||
self.debug(result)
|
|
||||||
|
for c in cmds:
|
||||||
except Exception:
|
self.debug(c)
|
||||||
self.fail("SSH failed for Virtual machine: %s" %
|
result = ssh_client.execute(c)
|
||||||
self.virtual_machine.ipaddress)
|
self.debug(result)
|
||||||
|
|
||||||
if str(result[0]).index("No such file or directory") == -1:
|
except Exception:
|
||||||
self.fail("Check the random data has be delete from temp file!")
|
self.fail("SSH failed for Virtual machine: %s" %
|
||||||
|
self.virtual_machine.ipaddress)
|
||||||
time.sleep(self.services["sleep"])
|
|
||||||
|
if str(result[0]).index("No such file or directory") == -1:
|
||||||
list_snapshot_response = VmSnapshot.list(self.apiclient,vmid=self.virtual_machine.id,listall=True)
|
self.fail("Check the random data has be delete from temp file!")
|
||||||
|
|
||||||
self.assertEqual(
|
time.sleep(self.services["sleep"])
|
||||||
isinstance(list_snapshot_response, list),
|
|
||||||
True,
|
list_snapshot_response = VmSnapshot.list(self.apiclient,vmid=self.virtual_machine.id,listall=True)
|
||||||
"Check list response returns a valid list"
|
|
||||||
)
|
self.assertEqual(
|
||||||
self.assertNotEqual(
|
isinstance(list_snapshot_response, list),
|
||||||
list_snapshot_response,
|
True,
|
||||||
None,
|
"Check list response returns a valid list"
|
||||||
"Check if snapshot exists in ListSnapshot"
|
)
|
||||||
)
|
self.assertNotEqual(
|
||||||
|
list_snapshot_response,
|
||||||
self.assertEqual(
|
None,
|
||||||
list_snapshot_response[0].state,
|
"Check if snapshot exists in ListSnapshot"
|
||||||
"Ready",
|
)
|
||||||
"Check the snapshot of vm is ready!"
|
|
||||||
)
|
self.assertEqual(
|
||||||
|
list_snapshot_response[0].state,
|
||||||
VmSnapshot.revertToSnapshot(self.apiclient,list_snapshot_response[0].id)
|
"Ready",
|
||||||
|
"Check the snapshot of vm is ready!"
|
||||||
list_vm_response = list_virtual_machines(
|
)
|
||||||
self.apiclient,
|
|
||||||
id=self.virtual_machine.id
|
VmSnapshot.revertToSnapshot(self.apiclient,list_snapshot_response[0].id)
|
||||||
)
|
|
||||||
|
list_vm_response = list_virtual_machines(
|
||||||
self.assertEqual(
|
self.apiclient,
|
||||||
list_vm_response[0].state,
|
id=self.virtual_machine.id
|
||||||
"Stopped",
|
)
|
||||||
"Check the state of vm is Stopped!"
|
|
||||||
)
|
self.assertEqual(
|
||||||
|
list_vm_response[0].state,
|
||||||
cmd = startVirtualMachine.startVirtualMachineCmd()
|
"Stopped",
|
||||||
cmd.id = list_vm_response[0].id
|
"Check the state of vm is Stopped!"
|
||||||
self.apiclient.startVirtualMachine(cmd)
|
)
|
||||||
|
|
||||||
time.sleep(self.services["sleep"])
|
cmd = startVirtualMachine.startVirtualMachineCmd()
|
||||||
|
cmd.id = list_vm_response[0].id
|
||||||
try:
|
self.apiclient.startVirtualMachine(cmd)
|
||||||
ssh_client = self.virtual_machine.get_ssh_client(reconnect=True)
|
|
||||||
|
time.sleep(self.services["sleep"])
|
||||||
cmds = [
|
|
||||||
"cat %s/%s" % (self.services["test_dir"], self.services["random_data"])
|
try:
|
||||||
]
|
ssh_client = self.virtual_machine.get_ssh_client(reconnect=True)
|
||||||
|
|
||||||
for c in cmds:
|
cmds = [
|
||||||
self.debug(c)
|
"cat %s/%s" % (self.services["test_dir"], self.services["random_data"])
|
||||||
result = ssh_client.execute(c)
|
]
|
||||||
self.debug(result)
|
|
||||||
|
for c in cmds:
|
||||||
except Exception:
|
self.debug(c)
|
||||||
self.fail("SSH failed for Virtual machine: %s" %
|
result = ssh_client.execute(c)
|
||||||
self.virtual_machine.ipaddress)
|
self.debug(result)
|
||||||
|
|
||||||
self.assertEqual(
|
except Exception:
|
||||||
self.random_data_0,
|
self.fail("SSH failed for Virtual machine: %s" %
|
||||||
result[0],
|
self.virtual_machine.ipaddress)
|
||||||
"Check the random data is equal with the ramdom file!"
|
|
||||||
)
|
self.assertEqual(
|
||||||
@attr(tags=["advanced", "advancedns", "smoke"])
|
self.random_data_0,
|
||||||
def test_03_delete_vm_snapshots(self):
|
result[0],
|
||||||
|
"Check the random data is equal with the ramdom file!"
|
||||||
list_snapshot_response = VmSnapshot.list(self.apiclient,vmid=self.virtual_machine.id,listall=True)
|
)
|
||||||
|
|
||||||
self.assertEqual(
|
@attr(tags=["advanced", "advancedns", "smoke"])
|
||||||
isinstance(list_snapshot_response, list),
|
def test_03_delete_vm_snapshots(self):
|
||||||
True,
|
"""Test to delete vm snapshots
|
||||||
"Check list response returns a valid list"
|
"""
|
||||||
)
|
|
||||||
self.assertNotEqual(
|
list_snapshot_response = VmSnapshot.list(self.apiclient,vmid=self.virtual_machine.id,listall=True)
|
||||||
list_snapshot_response,
|
|
||||||
None,
|
self.assertEqual(
|
||||||
"Check if snapshot exists in ListSnapshot"
|
isinstance(list_snapshot_response, list),
|
||||||
)
|
True,
|
||||||
"""
|
"Check list response returns a valid list"
|
||||||
cmd = deleteVMSnapshot.deleteVMSnapshotCmd()
|
)
|
||||||
cmd.vmsnapshotid = list_snapshot_response[0].id
|
self.assertNotEqual(
|
||||||
self.apiclient.deleteVMSnapshot(cmd)
|
list_snapshot_response,
|
||||||
"""
|
None,
|
||||||
VmSnapshot.deleteVMSnapshot(self.apiclient,list_snapshot_response[0].id)
|
"Check if snapshot exists in ListSnapshot"
|
||||||
|
)
|
||||||
time.sleep(self.services["sleep"]*3)
|
VmSnapshot.deleteVMSnapshot(self.apiclient,list_snapshot_response[0].id)
|
||||||
|
|
||||||
list_snapshot_response = VmSnapshot.list(self.apiclient,vmid=self.virtual_machine.id,listall=True)
|
time.sleep(self.services["sleep"]*3)
|
||||||
|
|
||||||
self.assertEqual(
|
list_snapshot_response = VmSnapshot.list(self.apiclient,vmid=self.virtual_machine.id,listall=True)
|
||||||
list_snapshot_response,
|
|
||||||
None,
|
self.assertEqual(
|
||||||
"Check list vm snapshot has be deleted"
|
list_snapshot_response,
|
||||||
)
|
None,
|
||||||
|
"Check list vm snapshot has be deleted"
|
||||||
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user