def test_run_invalid_plan_name(self): action = plan.CreatePlanAction("invalid_underscore") result = action.run() error_str = ("Unable to create plan. The plan name must only contain " "letters, numbers or dashes") # don't bother checking the exact error (python versions different) self.assertEqual(result.error.split(':')[0], error_str)
def test_run_invalid_yaml(self): self.swift.get_object.return_value = ({}, YAML_CONTENTS_INVALID) action = plan.CreatePlanAction(self.container_name) result = action.run() error_str = 'Error parsing the yaml file' self.assertEqual(result.error.split(':')[0], error_str)
def test_run_missing_key(self): self.swift.get_object.return_value = ({}, YAML_CONTENTS_MISSING_KEY) action = plan.CreatePlanAction(self.container_name) result = action.run() error_str = ("%s missing key: environments" % self.plan_environment_name) self.assertEqual(result.error, error_str)
def test_run_with_missing_key(self): self.swift.get_object.return_value = ({}, INVALID_MAPPING_CONTENTS) action = plan.CreatePlanAction(self.container_name) result = action.run() error_str = "capabilities-map.yaml missing key: 'root_template'" self.assertEqual(result.error, error_str)
def test_run_missing_file(self): self.swift.get_object.side_effect = swiftexceptions.ClientException( self.plan_environment_name) action = plan.CreatePlanAction(self.container_name) result = action.run() error_str = ('File missing from container: %s' % self.plan_environment_name) self.assertEqual(result.error, error_str)
def test_run_with_no_file(self): self.swift.get_object.side_effect = swiftexceptions.ClientException( 'atest2') action = plan.CreatePlanAction(self.container_name) result = action.run() error_str = 'File missing from container: atest2' self.assertEqual(result.error, error_str)
def test_run_with_invalid_string(self): self.swift.get_object.return_value = ({}, 'this is just a string') action = plan.CreatePlanAction(self.container_name) result = action.run() error_str = 'Error occurred creating plan' # don't bother checking the exact error (python versions different) self.assertEqual(result.error.split(':')[0], error_str)
def test_run_with_invalid_yaml(self): self.swift.get_object.return_value = ({}, 'invalid: %') action = plan.CreatePlanAction(self.container_name) result = action.run() error_str = 'Error parsing the yaml file' # don't bother checking the exact yaml error (it's long) self.assertEqual(result.error.split(':')[0], error_str)
def test_run_mistral_env_already_exists(self): self.mistral.environments.get.side_effect = None self.mistral.environments.get.return_value = 'test-env' action = plan.CreatePlanAction(self.container_name) result = action.run() error_str = ("Unable to create plan. The Mistral environment already " "exists") self.assertEqual(result.error, error_str) self.mistral.environments.create.assert_not_called()
def test_run_success(self): action = plan.CreatePlanAction(self.container_name) action.run() self.swift.get_object.assert_called_once_with( self.container_name, self.plan_environment_name) self.swift.delete_object.assert_called_once() self.mistral.environments.create.assert_called_once_with( name='Test-container-3', variables=JSON_CONTENTS)
def test_run(self): action = plan.CreatePlanAction(self.container_name) action.run() self.swift.get_object.assert_called_once_with(self.container_name, self.capabilities_name) self.mistral.environments.create.assert_called_once_with( name='test-container', variables=('{"environments":' ' [{"path": "/path/to/environment.yaml"}], ' '"template": "/path/to/overcloud.yaml"}'))
def test_run(self, get_workflow_client_mock, get_obj_client_mock): # setup swift swift = mock.MagicMock() swift.get_object.return_value = ({}, MAPPING_YAML_CONTENTS) get_obj_client_mock.return_value = swift # setup mistral mistral = mock.MagicMock() get_workflow_client_mock.return_value = mistral # Test action = plan.CreatePlanAction(self.container_name) action.run() # verify swift.get_object.assert_called_once_with(self.container_name, self.capabilities_name) mistral.environments.create.assert_called_once_with( name='test-container', variables=('{"environments":' ' [{"path": "/path/to/environment.yaml"}], ' '"template": "/path/to/overcloud.yaml"}'))