Пример #1
0
    def test_create_snapshot_and_attach_volume(self):
        fake_volume = mock.MagicMock()
        fake_snapshot = mock.MagicMock()
        fake_server = mock.MagicMock()
        fake_attach = mock.MagicMock()
        scenario = volumes.CreateSnapshotAndAttachVolume(self._get_context())

        scenario._attach_volume = mock.MagicMock(return_value=fake_attach)
        scenario._detach_volume = mock.MagicMock()
        scenario._boot_server = mock.MagicMock(return_value=fake_server)
        scenario._delete_server = mock.MagicMock()
        scenario._create_volume = mock.MagicMock(return_value=fake_volume)
        scenario._delete_volume = mock.MagicMock()
        scenario._create_snapshot = mock.MagicMock(return_value=fake_snapshot)
        scenario._delete_snapshot = mock.MagicMock()

        self.clients("nova").servers.get = mock.MagicMock(
            return_value=fake_server)

        scenario.run()

        self.assertTrue(scenario._create_volume.called)
        scenario._create_snapshot.assert_called_once_with(
            fake_volume.id, False)
        scenario._delete_snapshot.assert_called_once_with(fake_snapshot)
        scenario._attach_volume.assert_called_once_with(
            fake_server, fake_volume)
        scenario._detach_volume.assert_called_once_with(
            fake_server, fake_volume, fake_attach)
        scenario._delete_volume.assert_called_once_with(fake_volume)
Пример #2
0
    def test_create_snapshot_and_attach_volume_use_volume_type_with_name(
            self, mock_choice):
        mock_service = self.mock_cinder.return_value

        scenario = volumes.CreateSnapshotAndAttachVolume(self._get_context())
        scenario.get_random_server = mock.MagicMock()
        scenario._attach_volume = mock.MagicMock()
        scenario._detach_volume = mock.MagicMock()
        scenario.run(volume_type="type")

        fake_volume = mock_service.create_volume.return_value
        fake_attach = scenario._attach_volume.return_value
        fake_server = scenario.get_random_server.return_value
        fake_snapshot = mock_service.create_snapshot.return_value

        mock_service.create_volume.assert_called_once_with({
            "min": 1,
            "max": 5
        },
                                                           volume_type="type")
        mock_service.create_snapshot.assert_called_once_with(fake_volume.id,
                                                             force=False)
        mock_service.delete_snapshot.assert_called_once_with(fake_snapshot)
        scenario._attach_volume.assert_called_once_with(
            fake_server, fake_volume)
        scenario._detach_volume.assert_called_once_with(
            fake_server, fake_volume, fake_attach)
        mock_service.delete_volume.assert_called_once_with(fake_volume)
Пример #3
0
    def test_create_snapshot_and_attach_volume(self):
        mock_service = self.mock_cinder.return_value
        scenario = volumes.CreateSnapshotAndAttachVolume(self._get_context())
        scenario._boot_server = mock.MagicMock()
        scenario._attach_volume = mock.MagicMock()
        scenario._detach_volume = mock.MagicMock()
        scenario.run("img", "flavor")

        self.assertTrue(mock_service.create_volume.called)
        volume = mock_service.create_volume.return_value
        snapshot = mock_service.create_snapshot.return_value
        mock_service.create_snapshot.assert_called_once_with(volume.id,
                                                             force=False)
        mock_service.delete_snapshot.assert_called_once_with(snapshot)
        scenario._attach_volume.assert_called_once_with(
            scenario._boot_server.return_value, volume)
        scenario._detach_volume.assert_called_once_with(
            scenario._boot_server.return_value, volume)
        mock_service.delete_volume.assert_called_once_with(volume)
Пример #4
0
    def test_create_snapshot_and_attach_volume_use_volume_type_with_name(self):
        fake_volume = mock.MagicMock()
        fake_snapshot = mock.MagicMock()
        fake_server = mock.MagicMock()
        fake_attach = mock.MagicMock()

        scenario = volumes.CreateSnapshotAndAttachVolume(self._get_context())

        scenario._attach_volume = mock.MagicMock(return_value=fake_attach)
        scenario._detach_volume = mock.MagicMock()
        scenario._boot_server = mock.MagicMock(return_value=fake_server)
        scenario._delete_server = mock.MagicMock()
        scenario._create_volume = mock.MagicMock(return_value=fake_volume)
        scenario._delete_volume = mock.MagicMock()
        scenario._create_snapshot = mock.MagicMock(return_value=fake_snapshot)
        scenario._delete_snapshot = mock.MagicMock()
        fake = fake_type()

        self.clients("cinder").volume_types.list = mock.MagicMock(
            return_value=[fake])
        self.clients("nova").servers.get = mock.MagicMock(
            return_value=fake_server)

        scenario.run(volume_type="fake_volume_type")

        # Make sure create volume's second arg was the correct volume type.
        # fake or none (randomly selected)
        self.assertTrue(scenario._create_volume.called)
        vol_type = scenario._create_volume.call_args_list[0][1]["volume_type"]
        self.assertEqual(vol_type, "fake_volume_type")
        scenario._create_snapshot.assert_called_once_with(fake_volume.id,
                                                          False)
        scenario._delete_snapshot.assert_called_once_with(fake_snapshot)
        scenario._attach_volume.assert_called_once_with(fake_server,
                                                        fake_volume)
        scenario._detach_volume.assert_called_once_with(fake_server,
                                                        fake_volume,
                                                        fake_attach)
        scenario._delete_volume.assert_called_once_with(fake_volume)