def test_write(self): state = wrapper.State().instance self.assertEqual(state.state_file, None) state.state_file = tempfile.mkstemp(prefix='vchtest')[1] state.write() with open(state.state_file, 'rb') as f: json.loads(f.read())
def test_dict(self): """ Make sure the access to internal dictionary works """ state = wrapper.State().instance self.assertEqual(state['disks'], []) self.assertEqual(state['internal']['disk_ids'], {}) # check -- change -- check self.assertEqual(state['failed'], False) state['failed'] = True self.assertEqual(state['failed'], True)
def test_rhv_disk_path_vddk(self): state = wrapper.State().instance state.v2v_log = '/dev/null' state.machine_readable_log = '/dev/null' with wrapper.log_parser() as parser: parser.parse_line( state, b'nbdkit: debug: Opening file [store1] /path1.vmdk (ha-nfcssl://[store1] [email protected]:902)' ) # NOQA self.assertEqual(parser._current_path, '[store1] /path1.vmdk')
def test_singleton(self): state1 = wrapper.State().instance state2 = wrapper.State().instance # Internal dictionary key = 'abcdef' value = '123456' with self.assertRaises(KeyError): state1[key] with self.assertRaises(KeyError): state2[key] state1[key] = value self.assertEqual(state1[key], value) self.assertEqual(state2[key], value) # Property state1.state_file = None state2.state_file = None self.assertEqual(state1.state_file, None) self.assertEqual(state2.state_file, None) value = '/some/path' state1.state_file = value self.assertEqual(state2.state_file, value)
def test_rhv_disk_uuid(self): state = wrapper.State().instance state.v2v_log = '/dev/null' state.machine_readable_log = '/dev/null' with wrapper.log_parser() as parser: parser._current_disk = 0 path = '/path1' state['disks'] = [{'path': path}] parser.parse_line( state, b'disk.id = \'11111111-1111-1111-1111-111111111111\'') self.assertIn(path, state['internal']['disk_ids']) self.assertEqual(state['internal']['disk_ids'][path], b'11111111-1111-1111-1111-111111111111')
def test_progress(self): state = wrapper.State().instance state.v2v_log = '/dev/null' state.machine_readable_log = '/dev/null' with wrapper.log_parser() as parser: parser._current_disk = 0 parser._current_path = '/path1' state['disks'] = [{ 'path': '/path1', 'progress': 0.0, }] parser.parse_line(state, b' (10.42/100%)') self.assertEqual(state['disks'][0]['progress'], 10.42)
def test_vddk_basic(self): state = wrapper.State().instance state.machine_readable_log = '/some/path' data = self.VDDK_RHV.copy() expected = [ '-v', '-x', 'My Virtual', '--root', 'first', '--machine-readable=file:/some/path', '-i', 'libvirt', '-ic', 'esx://[email protected]?', '-it', 'vddk', '-io', 'vddk-libdir=/opt/vmware-vix-disklib-distrib', '-io', 'vddk-thumbprint=01:23:45:67:89:AB:CD:EA:DB:EE:F0:12:34:56:78:9A:BC:DE:F0:12', # NOQA E501 '--password-file', '/vmware/password', ] v2v_args, v2v_env = wrapper.prepare_command(data, []) self.assertEqual(v2v_args, expected)
def test_osp_volume_uuid(self): state = wrapper.State().instance state.v2v_log = '/dev/null' state.machine_readable_log = '/dev/null' with wrapper.log_parser() as parser: lines = [ br"openstack '--os-username=admin' '--os-identity-api-version=3' '--os-user-domain-name=Default' '--os-auth-url=http://10.19.2.25:5000//v3' '--os-volume-api-version=3' '--os-project-domain-name=Default' '--os-project-name=admin' '--os-password=100Root-' 'volume' 'show' '-f' 'json' '77c51545-f2a4-4bbf-8f04-169a15c23354'", # NOQA br"openstack '--os-username=admin' '--os-identity-api-version=3' '--os-user-domain-name=Default' '--os-auth-url=http://10.19.2.25:5000//v3' '--os-volume-api-version=3' '--os-project-domain-name=Default' '--os-project-name=admin' '--os-password=100Root-' 'volume' 'show' '-f' 'json' 'd85b7a6f-bffa-4b77-93df-912afd6e7014'", # NOQA ] for l in lines: parser.parse_line(state, l) self.assertIn(1, state['internal']['disk_ids']) self.assertIn(2, state['internal']['disk_ids']) self.assertEqual(state['internal']['disk_ids'][1], '77c51545-f2a4-4bbf-8f04-169a15c23354') self.assertEqual(state['internal']['disk_ids'][2], 'd85b7a6f-bffa-4b77-93df-912afd6e7014')
def test_disk_number(self): state = wrapper.State().instance state.v2v_log = '/dev/null' state.machine_readable_log = '/dev/null' with wrapper.log_parser() as parser: parser._current_disk = 0 parser._current_path = '/path1' state['disks'] = [ { 'path': '[store1] path1.vmdk' }, { 'path': '[store1] path2.vmdk' }, { 'path': '[store1] path3.vmdk' }, ] parser.parse_line(state, b'Copying disk 2/3 to /some/path') self.assertEqual(parser._current_disk, 1) self.assertIsNone(parser._current_path) self.assertEqual(state['disk_count'], 3)
def test_locate_disk(self): state = wrapper.State().instance state.v2v_log = '/dev/null' state.machine_readable_log = '/dev/null' with wrapper.log_parser() as parser: parser._current_disk = 0 parser._current_path = '[store1] path1.vmdk' state['disks'] = [ { 'path': '[store1] path2.vmdk' }, { 'path': '[store1] path1.vmdk' }, { 'path': '[store1] path3.vmdk' }, ] parser._locate_disk(state) self.assertEqual(state['disks'][0]['path'], '[store1] path1.vmdk') self.assertEqual(state['disks'][1]['path'], '[store1] path2.vmdk') self.assertEqual(state['disks'][2]['path'], '[store1] path3.vmdk')
def test_luks(self): state = wrapper.State().instance state.machine_readable_log = '/some/path' data = self.VDDK_RHV.copy() data['luks_keys_files'] = [ { 'device': '/dev/sda1', 'filename': '/tmp/luks/sda1', }, { 'device': '/dev/sda2', 'filename': '/tmp/luks/sda2', }, ] v2v_args, v2v_env = wrapper.prepare_command(data, []) self.assert_has_args( v2v_args, ['--key', '/dev/sda1:file:/tmp/luks/sda1'], 'Looking for LUKS key of device sda1 %r' % v2v_args) self.assert_has_args( v2v_args, ['--key', '/dev/sda2:file:/tmp/luks/sda2'], 'Looking for LUKS key of device sda2 %r' % v2v_args)