def test_get_free_device_path(self, p_ex_cmd, p_get_username): p_get_username.return_value = 'root' instance = r.InstanceResource({ 'instance_id': '123454321', 'node_group': {} }) stdout = """major minor #blocks name 8 0 488386584 vda 8 1 102400 vda1""" p_ex_cmd.return_value = (0, stdout) self.assertEqual(volumes._get_free_device_path(instance), '/dev/vdb') stdout = """major minor #blocks name 8 0 488386584 xvda 8 1 102400 xvda1""" p_ex_cmd.return_value = (0, stdout) self.assertEqual(volumes._get_free_device_path(instance), '/dev/xvdb') stdout = "major minor #blocks name\n" for idx in range(0, 26): line = " 8 0 488386584 vd" + chr(ord('a') + idx) + '\n' stdout += line p_ex_cmd.return_value = (0, stdout) self.assertRaises(RuntimeError, volumes._get_free_device_path, instance) p_ex_cmd.side_effect = ex.RemoteCommandException('cmd') self.assertRaises(ex.RemoteCommandException, volumes._get_free_device_path, instance)
def test_await_attach_volume(self, dev_paths, p_sleep): dev_paths.return_value = ['/dev/vda', '/dev/vdb'] p_sleep.return_value = None instance = r.InstanceResource({'instance_id': '123454321', 'instance_name': 'instt'}) self.assertIsNone(volumes._await_attach_volume(instance, '/dev/vdb')) self.assertRaises(RuntimeError, volumes._await_attach_volume, instance, '/dev/vdc')
def test_mount_volume(self, p_ex_cmd): instance = r.InstanceResource({'instance_id': '123454321'}) p_ex_cmd.return_value = (0, None) self.assertIsNone(volumes._mount_volume(instance, '123', '456')) self.assertEqual(p_ex_cmd.call_count, 3) p_ex_cmd.reset_mock() p_ex_cmd.side_effect = ex.RemoteCommandException('cmd') self.assertRaises(ex.RemoteCommandException, volumes._mount_volume, instance, '123', '456')
def test_mount_volume(self, p_ex_cmd): instance = r.InstanceResource({'instance_id': '123454321'}) p_ex_cmd.return_value = (0, None) self.assertIsNone(volumes._mount_volume(instance, '123', '456')) self.assertEqual(p_ex_cmd.call_count, 3) p_ex_cmd.reset_mock() p_ex_cmd.return_value = (1, None) self.assertRaises(RuntimeError, volumes._mount_volume, instance, '123', '456') self.assertEqual(p_ex_cmd.call_count, 3)
def test_mount_volume(self, p_ex_cmd, p_get_username, _acq, _rel, run_in_sub, start_sub, get_conn_params, p_close): p_get_username.return_value = 'root' instance = r.InstanceResource({ 'instance_id': '123454321', 'node_group': {} }) p_ex_cmd.return_value = (0, None) self.assertIsNone(volumes._mount_volume(instance, '123', '456')) self.assertEqual(p_ex_cmd.call_count, 3) p_ex_cmd.reset_mock() p_ex_cmd.side_effect = ex.RemoteCommandException('cmd') self.assertRaises(ex.RemoteCommandException, volumes._mount_volume, instance, '123', '456')
def test_get_free_device_path(self, p_ex_cmd): instance = r.InstanceResource({'instance_id': '123454321'}) p_ex_cmd.return_value = (1, None) self.assertRaises(RuntimeError, volumes._get_free_device_path, instance) stdout = """major minor #blocks name 8 0 488386584 vda 8 1 102400 vda1""" p_ex_cmd.return_value = (0, stdout) self.assertEqual(volumes._get_free_device_path(instance), '/dev/vdb') stdout = "major minor #blocks name\n" for idx in range(0, 26): line = " 8 0 488386584 vd" + chr(ord('a') + idx) + '\n' stdout += line p_ex_cmd.return_value = (0, stdout) self.assertRaises(RuntimeError, volumes._get_free_device_path, instance)