def test_create_cluster_with_existing_ct_and_list_clusters(self): context = self._get_context() scenario = clusters.CreateAndListClusters(context) kwargs = {"fakearg": "f"} fake_cluster1 = mock.Mock(uuid="a") fake_cluster2 = mock.Mock(uuid="b") fake_cluster3 = mock.Mock(uuid="c") scenario._create_cluster = mock.Mock(return_value=fake_cluster1) scenario._list_clusters = mock.Mock( return_value=[fake_cluster1, fake_cluster2, fake_cluster3]) run_kwargs = kwargs.copy() run_kwargs["cluster_template_uuid"] = "existing_cluster_template_uuid" # Positive case scenario.run(2, **run_kwargs) scenario._create_cluster.assert_called_once_with( "existing_cluster_template_uuid", 2, keypair=mock.ANY, **kwargs) scenario._list_clusters.assert_called_once_with(**kwargs) # Negative case1: cluster isn't created scenario._create_cluster.return_value = None self.assertRaises(exceptions.RallyAssertionError, scenario.run, 2, **run_kwargs) scenario._create_cluster.assert_called_with( "existing_cluster_template_uuid", 2, keypair=mock.ANY, **kwargs) # Negative case2: created cluster not in the list of available clusters scenario._create_cluster.return_value = mock.Mock(uuid="foo") self.assertRaises(exceptions.RallyAssertionError, scenario.run, 2, **run_kwargs) scenario._create_cluster.assert_called_with( "existing_cluster_template_uuid", 2, keypair=mock.ANY, **kwargs) scenario._list_clusters.assert_called_with(**kwargs)
def test_create_and_list_clusters(self): context = self._get_context() scenario = clusters.CreateAndListClusters(context) fake_cluster = mock.Mock() kwargs = {"fakearg": "f"} scenario._create_cluster = mock.Mock(return_value=fake_cluster) scenario._list_clusters = mock.Mock(return_value=[fake_cluster, mock.Mock(), mock.Mock()]) # Positive case scenario.run(2, **kwargs) scenario._create_cluster.assert_called_once_with( "rally_cluster_template_uuid", 2, **kwargs) scenario._list_clusters.assert_called_once_with(**kwargs) # Negative case1: cluster isn't created scenario._create_cluster.return_value = None self.assertRaises(exceptions.RallyAssertionError, scenario.run, 2, **kwargs) scenario._create_cluster.assert_called_with( "rally_cluster_template_uuid", 2, **kwargs) # Negative case2: created cluster not in the list of available clusters scenario._create_cluster.return_value = mock.MagicMock() self.assertRaises(exceptions.RallyAssertionError, scenario.run, 2, **kwargs) scenario._create_cluster.assert_called_with( "rally_cluster_template_uuid", 2, **kwargs) scenario._list_clusters.assert_called_with(**kwargs)
def test_create_and_list_clusters(self): context = self._get_context() scenario = clusters.CreateAndListClusters(context) fake_cluster = mock.Mock() kwargs = {"fakearg": "f"} scenario._create_cluster = mock.Mock(return_value=fake_cluster) scenario._list_clusters = mock.Mock() scenario.run(2, **kwargs) scenario._create_cluster.assert_called_once_with( "rally_cluster_template_uuid", 2, **kwargs) scenario._list_clusters.assert_called_once_with(**kwargs)
def test_create_cluster_with_existing_ct_and_list_clusters(self): scenario = clusters.CreateAndListClusters() kwargs = { "cluster_template_uuid": "existing_cluster_template_uuid", "fakearg": "f" } fake_cluster = mock.Mock() scenario._create_cluster = mock.Mock(return_value=fake_cluster) scenario._list_clusters = mock.Mock() scenario.run(2, **kwargs) scenario._create_cluster.assert_called_once_with( "existing_cluster_template_uuid", 2, **kwargs) scenario._list_clusters.assert_called_once_with(**kwargs)