def test_restore_with_bad_param_exception(self): self.env_object.status = 'Ready' self.mock_beanstalk.get_environment.return_value = self.env_object self.mock_beanstalk.rebuild_environment.side_effect = [ InvalidParameterValueError('Could not rebuild environment some-name because the cname is taken')] self.assertRaises(InvalidParameterValueError, restoreops.restore, self.env_id)
def restore(env_id): validate_restore(env_id) try: request_id = elasticbeanstalk.rebuild_environment(env_id=env_id) except InvalidParameterValueError as e: message = e.message.replace('rebuild', 'restore') raise InvalidParameterValueError(message) commonops.wait_for_success_events(request_id, timeout_in_minutes=None, can_abort=True)
def validate_restore(env_id): """ Do client side validation because rebuild will rebuild a running environments as well """ env = elasticbeanstalk.get_environment(env_id=env_id, include_deleted=True, deleted_back_to=get_date_cutoff()) if env.status != 'Terminated': raise InvalidParameterValueError('Environment {0} ({1}) is currently {2}, must be "Terminated" to restore' .format(env.name, env.id, env.status))
def test_create_new_environment_app_notexists(self): self.mock_elasticbeanstalk.create_environment.side_effect = [ InvalidParameterValueError('Application \'app-name\' already exists.'), ] try: env_request = CreateEnvironmentRequest( app_name='app-name', env_name='env-name', ) createops.create_env(env_request, interactive=True) self.fail('Should have thrown InvalidParameterValueError') except InvalidParameterValueError: pass
def test_create_new_environment_cname_taken_script(self): self.mock_elasticbeanstalk.create_environment.side_effect = [ InvalidParameterValueError('DNS name (cname) is not available.'), ] try: env_request = CreateEnvironmentRequest( app_name='app-name', env_name='env-name', ) createops.create_env(env_request, interactive=False) self.fail('Should have thrown InvalidParameterValueError') except InvalidParameterValueError: pass
def test_create_new_environment_cname_taken(self): self.mock_elasticbeanstalk.create_environment.side_effect = [ InvalidParameterValueError('DNS name (cname) is not available.'), None, ] self.mock_input.return_value = 'new-cname' env_request = CreateEnvironmentRequest( app_name='app-name', env_name='env-name', ) createops.create_env(env_request, interactive=True) self.assertEqual(self.mock_elasticbeanstalk.create_environment.call_count, 2)
def test_create_new_environment_envname_taken(self, mock_names): mock_names.return_value = ['my-env', 'my-env2'] self.mock_elasticbeanstalk.create_environment.side_effect = [ InvalidParameterValueError('Environment env-name already exists.'), None, ] self.mock_input.return_value = 'new-env-name' env_request = CreateEnvironmentRequest( app_name='app-name', env_name='env-name', ) createops.create_env(env_request, interactive=True) self.assertEqual(self.mock_elasticbeanstalk.create_environment.call_count, 2)