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 setUp(self): super(VLANBasicTest, self).setUp() self.client = cr.VLAN() self.dump_response = DumpResponse(clients=[self.client])
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'])
def test_servers_operations(self): dc = cr.Drive() sc = cr.Server() vc = cr.VLAN() puuid, p_pass = self._get_persistent_image_uuid_and_pass() LOG.debug('Get a vlan from the account') all_vlans = vc.list() if not all_vlans: raise SkipTest('There is no vlan in the acceptance test account') vlan = all_vlans[0] LOG.debug('Clone the persistent image') d1 = dc.clone(puuid, {'name': 'test_atom_clone_1'}) self._wait_for_status(d1['uuid'], status='unmounted', timeout=self.TIMEOUT_DRIVE_CLONING, client=dc) g_def = { "name": "test_server", "cpu": 1000, "mem": 1024**3, 'vnc_password': '******', 'drives': [ { "device": "virtio", "dev_channel": "0:0", "drive": d1['uuid'], "boot_order": 1 }, ], "nics": [{ "ip_v4_conf": { "ip": None, "conf": "dhcp" }, "model": "virtio", }, { "model": "virtio", "vlan": vlan['uuid'], }], } LOG.debug('Creating guest with drive') g1 = sc.create(g_def) self._wait_for_status(d1['uuid'], 'mounted', client=dc) LOG.debug('Clone the guest') g2 = sc.clone(g1['uuid']) self._wait_for_status(g2['uuid'], 'stopped', client=sc) LOG.debug('Check if the drive is active ( mounted )') d2_uuid = g2['drives'][0]['drive']['uuid'] self._wait_for_status(d2_uuid, 'mounted', client=dc) LOG.debug('Start both guests') sc.start(g1['uuid']) sc.start(g2['uuid']) self._wait_for_status(g1['uuid'], 'running', client=sc) self._wait_for_status(g2['uuid'], 'running', client=sc) LOG.debug('Refetch guest configurations') g1 = sc.get(g1['uuid']) g2 = sc.get(g2['uuid']) LOG.debug('Get the assigned ips') ip1 = g1['nics'][0]['runtime']['ip_v4']["uuid"] ip2 = g2['nics'][0]['runtime']['ip_v4']["uuid"] self._wait_for_open_socket(ip1, 22, timeout=60, close_on_success=True) self._wait_for_open_socket(ip2, 22, timeout=40, close_on_success=True) from fabric.api import settings as fabric_settings from fabric import tasks, api fab_kwargs = { "warn_only": True, "abort_on_prompts": True, "use_ssh_config": p_pass is None } LOG.debug('Using fabric config {}'.format(fab_kwargs)) if p_pass is not None: fab_kwargs['password'] = p_pass LOG.debug( 'Using a password to SSH to the servers ( not using ssh config )' ) with fabric_settings(**fab_kwargs): LOG.debug('Changing hostnames and restarting avahi on guest 1') set_hostname = 'hostname {} && service avahi-daemon restart' tasks.execute(api.run, set_hostname.format("atom1"), hosts=["root@%s" % ip1]) LOG.debug('Changing hostnames and restarting avahi on guest 2') tasks.execute(api.run, set_hostname.format("atom2"), hosts=["root@%s" % ip2]) LOG.debug('Ping the two hosts via private network') ping_res = tasks.execute(api.run, "ping atom2.local -c 1", hosts=["root@%s" % ip1]) self.assertEqual(ping_res.values()[0].return_code, 0, 'Could not ping host atom2 from atom1') LOG.debug('Halt both servers') tasks.execute(api.run, "halt", hosts=["root@%s" % ip1, "root@%s" % ip2]) LOG.debug('Wait for complete shutdown') self._wait_for_status(g1['uuid'], 'stopped', client=sc, timeout=40) self._wait_for_status(g2['uuid'], 'stopped', client=sc) LOG.debug('Deleting both guests') sc.delete(g1['uuid']) sc.delete(g2['uuid']) LOG.debug('Deleting both drives') dc.delete(d1['uuid']) dc.delete(d2_uuid) self._wait_deleted(d1['uuid'], client=dc) self._wait_deleted(d2_uuid, client=dc)
def test_servers_operations(self): dc = cr.Drive() sc = cr.Server() vc = cr.VLAN() puuid, p_pass = self._get_persistent_image_uuid_and_pass() LOG.debug('Get a vlan from the account') all_vlans = vc.list() if not all_vlans: raise SkipTest('There is no vlan in the acceptance test account') vlan = all_vlans[0] LOG.debug('Clone the persistent image') d1 = dc.clone(puuid, {'name': 'test_atom_clone_1'}) self._wait_for_status(d1['uuid'], status='unmounted', timeout=self.TIMEOUT_DRIVE_CLONING, client=dc) g_def = { "name": "test_server", "cpu": 1000, "mem": 1024**3, 'vnc_password': '******', 'drives': [ { "device": "virtio", "dev_channel": "0:0", "drive": d1['uuid'], "boot_order": 1 }, ], "nics": [{ "ip_v4_conf": { "ip": None, "conf": "dhcp" }, "model": "virtio", }, { "model": "virtio", "vlan": vlan['uuid'], }], } LOG.debug('Creating guest with drive') g1 = sc.create(g_def) self._wait_for_status(d1['uuid'], 'mounted', client=dc) LOG.debug('Clone the guest') g2 = sc.clone(g1['uuid']) self._wait_for_status(g2['uuid'], 'stopped', client=sc) LOG.debug('Check if the drive is active ( mounted )') d2_uuid = g2['drives'][0]['drive']['uuid'] self._wait_for_status(d2_uuid, 'mounted', client=dc) LOG.debug('Start both guests') sc.start(g1['uuid']) sc.start(g2['uuid']) self._wait_for_status(g1['uuid'], 'running', client=sc) self._wait_for_status(g2['uuid'], 'running', client=sc) LOG.debug('Refetch guest configurations') g1 = sc.get(g1['uuid']) g2 = sc.get(g2['uuid']) LOG.debug('Get the assigned ips') ip1 = g1['nics'][0]['runtime']['ip_v4']["uuid"] ip2 = g2['nics'][0]['runtime']['ip_v4']["uuid"] self._wait_for_open_socket(ip1, 22, timeout=300, close_on_success=True) self._wait_for_open_socket(ip2, 22, timeout=300, close_on_success=True) from fabric import Connection LOG.debug( 'Using a password to SSH to the servers ( not using ssh config )') self.ssh_host1 = "root@" + ip1 connection_host1 = Connection(host=self.ssh_host1, connect_kwargs={"password": p_pass}) self.ssh_host2 = "root@" + ip2 connection_host2 = Connection(host=self.ssh_host2, connect_kwargs={"password": p_pass}) LOG.debug('Changing hostnames and restarting avahi on guest 1') self.run_command = 'hostname {} && service avahi-daemon restart'.format( "atom1") self.cmd_exec_res = connection_host1.run( self.run_command).stderr.replace('\n', '') print(self.cmd_exec_res) LOG.debug('Changing hostnames and restarting avahi on guest 2') self.run_command = 'hostname {} && service avahi-daemon restart'.format( "atom2") self.cmd_exec_res = connection_host2.run( self.run_command).stderr.replace('\n', '') print(self.cmd_exec_res) #LOG.debug('Ping the two hosts via private network') #self.run_command = 'ping atom2.local -c 1' #cmd_exec_res = connection_host1.run(self.run_command).stdout.replace('\n', '') #self.assertEqual(cmd_exec_res, 0, 'Could not ping host atom2 from atom1') LOG.debug('poweroff both servers') self.run_command = 'poweroff' with self.assertRaises(UnexpectedExit): self.cmd_exec_res = connection_host1.run(self.run_command) print(self.cmd_exec_res) self.run_command = 'poweroff' with self.assertRaises(UnexpectedExit): self.cmd_exec_res = connection_host2.run(self.run_command) print(self.cmd_exec_res) LOG.debug('Wait for complete shutdown') self._wait_for_status(g1['uuid'], 'stopped', client=sc, timeout=40) self._wait_for_status(g2['uuid'], 'stopped', client=sc) LOG.debug('Deleting both guests') sc.delete(g1['uuid']) sc.delete(g2['uuid']) LOG.debug('Deleting both drives') dc.delete(d1['uuid']) dc.delete(d2_uuid) self._wait_deleted(d1['uuid'], client=dc) self._wait_deleted(d2_uuid, client=dc)