1+ # Licensed to the Apache Software Foundation (ASF) under one
2+ # or more contributor license agreements. See the NOTICE file
3+ # distributed with this work for additional information
4+ # regarding copyright ownership. The ASF licenses this file
5+ # to you under the Apache License, Version 2.0 (the
6+ # "License"); you may not use this file except in compliance
7+ # with the License. You may obtain a copy of the License at
8+ #
9+ # http://www.apache.org/licenses/LICENSE-2.0
10+ #
11+ # Unless required by applicable law or agreed to in writing,
12+ # software distributed under the License is distributed on an
13+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+ # KIND, either express or implied. See the License for the
15+ # specific language governing permissions and limitations
16+ # under the License.
17+
18+ #Test from the Marvin - Testing in Python wiki
19+ from marvin .codes import FAILED
20+
21+ #All tests inherit from cloudstackTestCase
22+ from marvin .cloudstackTestCase import cloudstackTestCase
23+
24+ #Import Integration Libraries
25+
26+ #base - contains all resources as entities and defines create, delete, list operations on them
27+ from marvin .lib .base import Account , VirtualMachine , ServiceOffering
28+
29+ #utils - utility classes for common cleanup, external library wrappers etc
30+ from marvin .lib .utils import cleanup_resources
31+
32+ #common - commonly used methods for all tests are listed here
33+ from marvin .lib .common import get_zone , get_domain , get_template
34+
35+ from marvin .cloudstackAPI .listNics import listNicsCmd
36+
37+
38+ from nose .plugins .attrib import attr
39+
40+ class TestDeployVM (cloudstackTestCase ):
41+ """Test deploy a VM into a user account
42+ """
43+
44+ def setUp (self ):
45+ self .testdata = self .testClient .getParsedTestDataConfig ()
46+ self .apiclient = self .testClient .getApiClient ()
47+
48+ # Get Zone, Domain and Default Built-in template
49+ self .domain = get_domain (self .apiclient )
50+ self .zone = get_zone (self .apiclient , self .testClient .getZoneForTests ())
51+ self .testdata ["mode" ] = self .zone .networktype
52+ self .template = get_template (self .apiclient , self .zone .id , self .testdata ["ostype" ])
53+
54+ if self .template == FAILED :
55+ assert False , "get_template() failed to return template with description %s" % self .testdata ["ostype" ]
56+
57+ #create a user account
58+ self .account = Account .create (
59+ self .apiclient ,
60+ self .testdata ["account" ],
61+ domainid = self .domain .id
62+ )
63+ #create a service offering
64+ self .service_offering = ServiceOffering .create (
65+ self .apiclient ,
66+ self .testdata ["service_offerings" ]["small" ]
67+ )
68+ #build cleanup list
69+ self .cleanup = [
70+ self .service_offering ,
71+ self .account
72+ ]
73+
74+ # Validate the following:
75+ # 1. Virtual Machine is accessible via SSH
76+ # 2. listVirtualMachines returns accurate information
77+
78+ self .virtual_machine = VirtualMachine .create (
79+ self .apiclient ,
80+ self .testdata ["virtual_machine" ],
81+ accountid = self .account .name ,
82+ zoneid = self .zone .id ,
83+ domainid = self .account .domainid ,
84+ serviceofferingid = self .service_offering .id ,
85+ templateid = self .template .id
86+ )
87+
88+ list_vms = VirtualMachine .list (self .apiclient , id = self .virtual_machine .id )
89+
90+ self .debug (
91+ "Verify listVirtualMachines response for virtual machine: %s" \
92+ % self .virtual_machine .id
93+ )
94+
95+ self .assertEqual (
96+ isinstance (list_vms , list ),
97+ True ,
98+ "List VM response was not a valid list"
99+ )
100+ self .assertNotEqual (
101+ len (list_vms ),
102+ 0 ,
103+ "List VM response was empty"
104+ )
105+
106+ vm = list_vms [0 ]
107+ self .assertEqual (
108+ vm .id ,
109+ self .virtual_machine .id ,
110+ "Virtual Machine ids do not match"
111+ )
112+ self .assertEqual (
113+ vm .name ,
114+ self .virtual_machine .name ,
115+ "Virtual Machine names do not match"
116+ )
117+ self .assertEqual (
118+ vm .state ,
119+ "Running" ,
120+ msg = "VM is not in Running state"
121+ )
122+
123+ @attr (tags = ['advanced' , 'basic' ], required_hardware = "false" )
124+ def test_list_nics (self ):
125+ list_vms = VirtualMachine .list (self .apiclient , id = self .virtual_machine .id )
126+ vmid = self .virtual_machine .id
127+ cmd = listNicsCmd ()
128+ cmd .virtualmachineid = vmid
129+ list_nics = self .apiclient .listNics (cmd )
130+
131+ nic = list_nics [0 ]
132+
133+ self .assertIsNotNone (
134+ nic .type ,
135+ "Nic Type is %s" % nic .type
136+ )
137+
138+ self .assertIsNotNone (
139+ nic .traffictype ,
140+ "Nic traffictype is %s" % nic .traffictype
141+ )
142+
143+ self .assertIsNotNone (
144+ nic .broadcasturi ,
145+ "Nic broadcasturi is %s" % nic .broadcasturi
146+ )
147+
148+ self .assertIsNotNone (
149+ nic .isolationuri ,
150+ "Nic isolationuri is %s" % nic .isolationuri
151+ )
152+
153+
154+ def tearDown (self ):
155+ try :
156+ cleanup_resources (self .apiclient , self .cleanup )
157+ except Exception as e :
158+ self .debug ("Warning! Exception in tearDown: %s" % e )
159+ return
0 commit comments