def test_overlapping_virtual_networks_are_separate(self): inst1 = self.test_client.create_instance( 'cirros', 1, 1024, [{ 'network_uuid': self.net_one['uuid'] }], [{ 'size': 8, 'base': 'cirros', 'type': 'disk' }], None, None) inst2 = self.test_client.create_instance( 'cirros', 1, 1024, [{ 'network_uuid': self.net_three['uuid'] }], [{ 'size': 8, 'base': 'cirros', 'type': 'disk' }], None, None) self.assertIsNotNone(inst1['uuid']) self.assertIsNotNone(inst2['uuid']) self._await_login_prompt(inst1['uuid']) self._await_login_prompt(inst2['uuid']) nics = self.test_client.get_instance_interfaces(inst2['uuid']) console = base.LoggingSocket(inst1['node'], inst1['console_port']) out = console.execute('ping -c 3 %s' % nics[0]['ipv4']) if not out.find('100% packet'): self.fail('Ping should have failed!\n\n%s' % out)
def test_default(self): inst = self.test_client.create_instance('cirros', 1, 1024, None, [{ 'size': 8, 'base': 'cirros', 'type': 'disk' }], None, None) self.assertIsNotNone(inst['uuid']) self._await_login_prompt(inst['uuid']) console = base.LoggingSocket(inst['node'], inst['console_port']) out = console.execute('df -h') if not out.find('vda'): self.fail('Disk is not virtio!\n\n%s' % out)
def test_ide(self): inst = self.test_client.create_instance( 'cirros', 1, 1024, None, [{ 'size': 8, 'base': 'sf://upload/system/cirros', 'type': 'disk', 'bus': 'ide' }], None, None) self.assertIsNotNone(inst['uuid']) self._await_login_prompt(inst['uuid']) console = base.LoggingSocket(self.test_client, inst) out = console.execute('df -h') if not out.find('sda'): self.fail('Disk is not IDE!\n\n%s' % out)
def test_complex(self): inst = self.test_client.create_instance( 'cirros', 1, 1024, None, [{ 'size': 8, 'base': 'cirros', 'type': 'disk', 'bus': 'ide' }, { 'size': 16, 'type': 'disk' }, { 'base': ('http://archive.ubuntu.com/ubuntu/dists/focal/main/' 'installer-amd64/current/legacy-images/netboot/mini.iso') }], None, None) self.assertIsNotNone(inst['uuid']) self._await_login_prompt(inst['uuid']) console = base.LoggingSocket(inst['node'], inst['console_port']) # Boot disk out = console.execute('dmesg | grep sda') if not out.find( '[sda] 16777216 512-byte logical blocks: (8.59 GB/8.00 GiB)'): self.fail('sda config is incorrect\n\n%s' % out) # config drive out = console.execute('dmesg | grep sdb') if not out.find('[sdb] Attached SCSI disk'): self.fail('sdb config is incorrect\n\n%s' % out) # 16gb empty data disk out = console.execute('dmesg | grep vda') if not out.find( '[vda] 33554432 512-byte logical blocks (17.2 GB/16.0 GiB)'): self.fail('vda config is incorrect\n\n%s' % out) # ISO as CDROM out = console.execute('dmesg | grep sr0') if not out.find('Attached scsi CD-ROM sr0'): self.fail('sr0 config is incorrect\n\n%s' % out) out = console.execute('sudo mount /dev/sr0 /mnt; ls /mnt') if not out.find('isolinux.bin'): self.fail('sr0 did not mount correctly\n\n%s' % out)
def test_multiple_disk_snapshots(self): inst = self.test_client.create_instance( 'cirros', 1, 1024, [ { 'network_uuid': self.net['uuid'] } ], [ { 'size': 8, 'base': 'cirros', 'type': 'disk' }, { 'size': 8, 'type': 'disk' }, { 'size': 8, 'base': 'cirros', 'type': 'cdrom' } ], None, None) self.assertIsNotNone(inst['uuid']) self.assertIsNotNone(inst['node']) console = base.LoggingSocket(inst['node'], inst['console_port']) console.await_login_prompt() snap1 = self.test_client.snapshot_instance(inst['uuid']) self.assertIsNotNone(snap1) snapshots = self.test_client.get_instance_snapshots(inst['uuid']) self.assertEqual(1, len(snapshots)) snap2 = self.test_client.snapshot_instance(inst['uuid'], all=True) self.assertIsNotNone(snap2) snapshots = self.test_client.get_instance_snapshots(inst['uuid']) self.assertEqual(3, len(snapshots)) for snap in snapshots: self.assertIn(snap['device'], ['vda', 'vdc']) self.assertEqual(inst['uuid'], snap['instance_uuid']) self.test_client.delete_instance(inst['uuid'])
def test_serial_console(self): inst = self.test_client.create_instance( 'cirros', 1, 1024, [{ 'network_uuid': self.net['uuid'] }], [{ 'size': 8, 'base': 'sf://upload/system/cirros', 'type': 'disk' }], None, None) self.assertIsNotNone(inst['uuid']) self.assertIsNotNone(inst['node']) self._await_login_prompt(inst['uuid']) console = base.LoggingSocket(self.test_client, inst) self.assertTrue(console.execute('uptime').find('load average'))
def test_specific_macaddress_request(self): inst = self.test_client.create_instance( 'cirros', 1, 1024, [{ 'network_uuid': self.net_four['uuid'], 'macaddress': '04:ed:33:c0:2e:6c' }], [{ 'size': 8, 'base': 'sf://upload/system/cirros', 'type': 'disk' }], None, None) self._await_instances_ready([inst['uuid']]) console = base.LoggingSocket(self.test_client, inst) out = console.execute('ip link') if not out.find('04:ed:33:c0:2e:6c'): self.fail('Requested macaddress not used!\n\n%s' % out)
def test_specific_macaddress_request(self): inst = self.test_client.create_instance( 'cirros', 1, 1024, [{ 'network_uuid': self.net_four['uuid'], 'macaddress': '04:ed:33:c0:2e:6c' }], [{ 'size': 8, 'base': 'cirros', 'type': 'disk' }], None, None) self.assertIsNotNone(inst['uuid']) self.assertIsNotNone(inst['node']) console = base.LoggingSocket(inst['node'], inst['console_port']) out = console.execute('ip link') if not out.find('04:ed:33:c0:2e:6c'): self.fail('Requested macaddress not used!\n\n%s' % out)
def test_single_virtual_networks_work(self): inst1 = self.test_client.create_instance( 'cirros', 1, 1024, [{ 'network_uuid': self.net_one['uuid'] }], [{ 'size': 8, 'base': 'sf://upload/system/cirros', 'type': 'disk' }], None, None) inst2 = self.test_client.create_instance( 'cirros', 1, 1024, [{ 'network_uuid': self.net_one['uuid'] }], [{ 'size': 8, 'base': 'sf://upload/system/cirros', 'type': 'disk' }], None, None) self.assertIsNotNone(inst1['uuid']) self.assertIsNotNone(inst2['uuid']) self._await_login_prompt(inst1['uuid']) self._await_login_prompt(inst2['uuid']) nics = self.test_client.get_instance_interfaces(inst2['uuid']) self.assertEqual(1, len(nics)) for iface in nics: self.assertEqual( 'created', iface['state'], 'Interface %s is not in correct state' % iface['uuid']) # Ping the other instance on this network console = base.LoggingSocket(self.test_client, inst1) out = console.execute('ping -c 3 %s' % nics[0]['ipv4']) if not out.find(' 0% packet'): self.fail('Ping should have worked!\n\n%s' % out) # Ping google (prove NAT works) out = console.execute('ping -c 3 8.8.8.8') if not out.find(' 0% packet'): self.fail('Ping should have worked!\n\n%s' % out)
def test_single_virtual_networks_work(self): inst1 = self.test_client.create_instance( 'cirros', 1, 1024, [{ 'network_uuid': self.net_one['uuid'] }], [{ 'size': 8, 'base': 'cirros', 'type': 'disk' }], None, None) inst2 = self.test_client.create_instance( 'cirros', 1, 1024, [{ 'network_uuid': self.net_one['uuid'] }], [{ 'size': 8, 'base': 'cirros', 'type': 'disk' }], None, None) self.assertIsNotNone(inst1['uuid']) self.assertIsNotNone(inst2['uuid']) self._await_login_prompt(inst1['uuid']) self._await_login_prompt(inst2['uuid']) nics = self.test_client.get_instance_interfaces(inst2['uuid']) # Ping the other instance on this network console = base.LoggingSocket(inst1['node'], inst1['console_port']) out = console.execute('ping -c 3 %s' % nics[0]['ipv4']) if not out.find(' 0% packet'): self.fail('Ping should have worked!\n\n%s' % out) # Ping google (prove NAT works) out = console.execute('ping -c 3 8.8.8.8') if not out.find(' 0% packet'): self.fail('Ping should have worked!\n\n%s' % out)
def test_simple(self): ud = """#!/bin/sh sudo echo 'banana' > /tmp/output""" inst = self.test_client.create_instance( 'cirros', 1, 1024, [{ 'network_uuid': self.net_one['uuid'] }, { 'network_uuid': self.net_one['uuid'] }], [{ 'size': 8, 'base': 'sf://upload/system/cirros', 'type': 'disk' }], 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCuGJ47be0/3EH/q1b/2AYdh' 'vTG/5L84QnKm3MhTO+cQGYfxw2AhPk6AOdHYPIp+t2wV/noc1eKCHN8n//T42' '4usEIQ/ODg9o2BeAhUU8S4qd6XSW5ihOknBZRnoQrYmAM6gUUvF4hLJ62Tzf/' 'h2Hi9Wl774DRDs/Il5pBJnt+AdAgLcnVgJJG8KtX3JnynwnBOTlbKnyIWmEnH' 'ZL+RH2+lIftsVXelLwq/bpzBWsg0JjjGvtuuKMMge0y3ZfsBA8/vLytaEV/vQ' 'k/osilJeAbYa7Ul1K65S5eC2G2Yx4rNKdx0nn4lK2o/2keN52pDhrJbmK4907' 'B50mWqtCFjsNULnfT5paInHRPgasKl007E0ZNNxhfXWieiVCUu/5zFiMPcWyB' '9YN60gp4lZSKB19GaURxtbKWlajfEakn3mTm9JQH5eU48XIaCh+LcptKYd6lD' 'BWeoicQzECQLMfnKuGpfoZsKbOTTeCzS0/q6guKLNgfXijpRf5uaZaTqQa18t' '8s= mikal@marvin"', str(base64.b64encode(ud.encode('utf-8')), 'utf-8')) self.assertIsNotNone(inst['uuid']) self._await_login_prompt(inst['uuid']) console = base.LoggingSocket(self.test_client, inst) out = console.execute('cat /tmp/output') if not out.find('banana'): self.fail('User data script did not run!\n\n%s' % out) out = console.execute('cat /home/cirros/.ssh/authorized_keys') if not out.find('elLwq/bpzBWsg0JjjGvtuuKMM'): self.fail('ssh key was not placed in authorized keys!\n\n%s' % out)
def test_simple(self): self.skip('Disabled because unreliable') ud = """#!/bin/sh sudo apt-get update sudo apt-get dist-upgrade -y sudo apt-get install apache2 -y sudo chmod ugo+rw /var/www/html/index.html echo 'Floating IPs work!' > /var/www/html/index.html """ inst = self.test_client.create_instance( 'floating', 1, 1024, [ { 'network_uuid': self.net['uuid'] }, ], [{ 'size': 20, 'base': 'sf://upload/system/ubuntu-2004', 'type': 'disk' }], None, str(base64.b64encode(ud.encode('utf-8')), 'utf-8')) self.assertIsNotNone(inst['uuid']) self._await_cloud_init_complete(inst['uuid']) # Wait for boot and cloud-init time.sleep(120) console = base.LoggingSocket(self.test_client, inst) out = console.execute('cat /var/www/html/index.html') if not out.find('Floating IPs work!'): self.fail('User data script did not run!\n\n%s' % out) ifaces = self.test_client.get_instance_interfaces(inst['uuid']) self.test_client.float_interface(ifaces[0]['uuid']) ifaces = self.test_client.get_instance_interfaces(inst['uuid']) self.assertNotEqual(None, ifaces[0]['floating']) # Because the user data in this test does a dist-upgrade and installs # a package, it can take a long time to run. This happens after the # instance presents its first login prompt (checked above), so we # need to sleep for a disturbingly long time just in case. time.sleep(300) attempts = 0 for _ in range(10): attempts += 1 try: r = requests.request('GET', 'http://%s/' % ifaces[0]['floating']) if r.status_code == 200: if r.text.find('Floating IPs work!') != -1: return print('Floating IPs test attempt failed, incorrect HTTP ' 'result') else: print('Floating IPs test attempt received HTTP status %s' % r.status_code) except Exception as e: print('Floating IPs test attempt failed with exception: %s' % e) time.sleep(30) self.fail('Incorrect result after %d attempts, instance was %s' % (attempts, inst['uuid']))
def test_extraneous_network_duplicates(self): dupnet = self.test_client.allocate_network('10.0.0.0/24', True, True, '%s-dups' % self.namespace) self._await_networks_ready([dupnet['uuid']]) try: inst_hyp1_vm1 = self.test_client.create_instance( 'dup1', 1, 1024, [{ 'network_uuid': dupnet['uuid'] }], [{ 'size': 8, 'base': 'sf://upload/system/cirros', 'type': 'disk' }], None, None, force_placement='sf-2') inst_hyp1_vm2 = self.test_client.create_instance( 'dup2', 1, 1024, [{ 'network_uuid': dupnet['uuid'] }], [{ 'size': 8, 'base': 'sf://upload/system/ubuntu-2004', 'type': 'disk' }], None, None, force_placement='sf-2') inst_hyp2_vm1 = self.test_client.create_instance( 'dup3', 1, 1024, [{ 'network_uuid': dupnet['uuid'] }], [{ 'size': 8, 'base': 'sf://upload/system/ubuntu-2004', 'type': 'disk' }], None, None, force_placement='sf-3') except apiclient.ResourceNotFoundException as e: self.skip('Target node does not exist. %s' % e) return self.assertIsNotNone(inst_hyp1_vm1['uuid']) self._await_login_prompt(inst_hyp1_vm1['uuid']) self.assertIsNotNone(inst_hyp1_vm2['uuid']) self._await_login_prompt(inst_hyp1_vm2['uuid']) self.assertIsNotNone(inst_hyp2_vm1['uuid']) self._await_login_prompt(inst_hyp2_vm1['uuid']) nics = self.test_client.get_instance_interfaces(inst_hyp1_vm2['uuid']) console = base.LoggingSocket(self.test_client, inst_hyp1_vm1) out = console.execute('ping -c 3 %s' % nics[0]['ipv4']) self.assertFalse('DUP' in out)