コード例 #1
0
ファイル: test_volumes.py プロジェクト: 1990ajay/rally
    def test_create_volume_from_snapshot(self):
        fake_snapshot = mock.MagicMock(id=1)
        fake_volume = mock.MagicMock()
        create_snapshot_args = {"force": False}
        scenario = volumes.CreateVolumeFromSnapshot(self._get_context())

        scenario._create_snapshot = mock.MagicMock(return_value=fake_snapshot)
        scenario._create_volume = mock.MagicMock(return_value=fake_volume)
        scenario._delete_snapshot = mock.MagicMock()
        scenario._delete_volume = mock.MagicMock()

        scenario.run(fakearg="f")

        scenario._create_snapshot.assert_called_once_with("uuid")
        scenario._create_volume.assert_called_once_with(
            1, snapshot_id=fake_snapshot.id, fakearg="f")
        scenario._delete_snapshot.assert_called_once_with(fake_snapshot)
        scenario._delete_volume.assert_called_once_with(fake_volume)

        scenario._create_snapshot.reset_mock()
        scenario._create_volume.reset_mock()
        scenario._delete_snapshot.reset_mock()
        scenario._delete_volume.reset_mock()

        scenario.run(do_delete=False,
                     create_snapshot_kwargs=create_snapshot_args,
                     fakearg="f")

        scenario._create_snapshot.assert_called_once_with(
            "uuid", **create_snapshot_args)
        scenario._create_volume.assert_called_once_with(
            1, snapshot_id=fake_snapshot.id, fakearg="f")
        self.assertFalse(scenario._delete_snapshot.called)
        self.assertFalse(scenario._delete_volume.called)
コード例 #2
0
ファイル: test_volumes.py プロジェクト: zhangdelong/rally
    def test_create_volume_from_snapshot(self):
        mock_service = self.mock_cinder.return_value
        create_snapshot_args = {"force": False}

        scenario = volumes.CreateVolumeFromSnapshot(self._get_context())
        scenario.run(fakearg="f")

        fake_snapshot = mock_service.create_snapshot.return_value
        fake_volume = mock_service.create_volume.return_value
        mock_service.create_snapshot.assert_called_once_with("uuid")
        mock_service.create_volume.assert_called_once_with(
            1, snapshot_id=fake_snapshot.id, fakearg="f")
        mock_service.delete_snapshot.assert_called_once_with(fake_snapshot)
        mock_service.delete_volume.assert_called_once_with(fake_volume)

        mock_service.create_snapshot.reset_mock()
        mock_service.create_volume.reset_mock()
        mock_service.delete_snapshot.reset_mock()
        mock_service.delete_volume.reset_mock()

        scenario.run(do_delete=False,
                     create_snapshot_kwargs=create_snapshot_args,
                     fakearg="f")

        mock_service.create_snapshot.assert_called_once_with(
            "uuid", **create_snapshot_args)
        mock_service.create_volume.assert_called_once_with(
            1, snapshot_id=fake_snapshot.id, fakearg="f")
        self.assertFalse(mock_service.delete_snapshot.called)
        self.assertFalse(mock_service.delete_volume.called)