def setUp(self): super(IPBasicTest, self).setUp() self.client = cr.IP() self.dump_response = DumpResponse(clients=[self.client])
def test_server_nics(self): server = self._create_a_server() subs_client = cr.Subscriptions() vlan_client = cr.VLAN() vlans = vlan_client.list() if not vlans: subs_client.create({ 'resource': 'vlan', 'amount': 1, 'period': '1 month' }) vlans = vlan_client.list() vlan_uuid = vlans[0]['uuid'] ip_client = cr.IP() ips = ip_client.list() free_ips = [ip for ip in ips if ip['server'] is None] if not free_ips: subs_client.create({ 'resource': 'ip', 'amount': 1, 'period': '1 month' }) ips = ip_client.list() free_ips = [ip for ip in ips if ip['server'] is None] ip_uuid = free_ips[0]['uuid'] server['nics'] = [{'vlan': vlan_uuid}] with DumpResponse(clients=[self.client], name='server_add_private_nic'): server = self.client.update(server['uuid'], server) server['nics'] = [{'ip_v4_conf': {'conf': 'dhcp'}, 'model': 'e1000'}] with DumpResponse(clients=[self.client], name='server_add_dhcp_nic'): server = self.client.update(server['uuid'], server) server['nics'] = [{ 'ip_v4_conf': { 'conf': 'dhcp' }, 'model': 'e1000' }, { 'vlan': vlan_uuid }] server = self.client.update(server['uuid'], server) with DumpResponse(clients=[self.client], name='server_get_two_nics'): server = self.client.get(server['uuid']) server['nics'][0]['ip_v4_conf'] = {'conf': 'static', 'ip': ip_uuid} with DumpResponse(clients=[self.client], name='server_change_nic_to_static'): server = self.client.update(server['uuid'], server) server['nics'] = [server['nics'][1], server['nics'][0]] with DumpResponse(clients=[self.client], name='server_rearrange_nics'): server = self.client.update(server['uuid'], server) private_mac = server['nics'][0]['mac'] server['nics'] = [{'ip_v4_conf': {'conf': 'dhcp'}, 'mac': private_mac}] with DumpResponse(clients=[self.client], name='server_del_and_change_nic'): server = self.client.update(server['uuid'], server) server['nics'] = [{'ip_v4_conf': {'conf': 'manual'}}] with DumpResponse(clients=[self.client], name='server_add_manual_nic'): server = self.client.update(server['uuid'], server) self.client.delete(server['uuid'])
def test_tags(self): with self.dump_response('tags_schema'): self.client.get_schema() sc = cr.Server() server1 = sc.create({ 'name': 'test_server1', 'cpu': 1000, 'mem': 512 * 1024**2, 'vnc_password': '******' }) server2 = sc.create({ 'name': 'test_server2', 'cpu': 1000, 'mem': 512 * 1024**2, 'vnc_password': '******' }) dc = cr.Drive() drive = dc.create({ 'name': 'test_drive', 'size': 1000**3, 'media': 'disk' }) ip = cr.IP().list()[0] vlan = cr.VLAN().list()[0] with self.dump_response('tags_create'): tag1 = self.client.create({'name': 'MyGroupOfThings'}) with self.dump_response('tags_create_with_resource'): tag2 = self.client.create({ 'name': 'TagCreatedWithResource', 'resources': [ server1['uuid'], server2['uuid'], drive['uuid'], ip['uuid'], vlan['uuid'] ] }) with self.dump_response('tags_list'): self.client.list() with self.dump_response('tags_list_detail'): self.client.list_detail() with self.dump_response('tags_get'): self.client.get(tag2['uuid']) with self.dump_response('tags_update_resources'): self.client.update( tag2['uuid'], { 'name': 'TagCreatedWithResource', 'resources': [server1['uuid'], drive['uuid']] }) server2['tags'] = [tag1['uuid'], tag2['uuid']] with DumpResponse(clients=[sc], name='tags_update_tag_from_resource'): sc.update(server2['uuid'], server2) with self.dump_response('tags_list_resource'): self.client.servers(tag1['uuid']) time.sleep(30) dc.delete(drive['uuid']) sc.delete(server1['uuid']) sc.delete(server2['uuid']) with self.dump_response('tags_delete'): self.client.delete(tag1['uuid']) self.client.delete(tag2['uuid'])