def test_create_stack_during_launch(self): task = LaunchStackTask() mock_heat_client = Mock() mock_heat_client.stacks.get.side_effect = [ HTTPNotFound, self.stacks['CREATE_IN_PROGRESS'], self.stacks['CREATE_IN_PROGRESS'], self.stacks['CREATE_COMPLETE'] ] mock_heat_client.stacks.create.return_value = { 'stack': { 'id': self.stack_name } } mock_verify_stack = Mock(return_value=('CREATE_COMPLETE', None, self.stack_ip)) with patch.multiple( task, sleep=0, get_heat_client=Mock(return_value=mock_heat_client), verify_stack=mock_verify_stack): res = task.run(self.stack_name, self.stack_template, self.stack_user, self.auth_url) assert res['status'] == 'CREATE_COMPLETE' mock_heat_client.stacks.create.assert_called_with( stack_name=self.stack_name, template=self.stack_template) mock_verify_stack.assert_called_with( self.stacks['CREATE_COMPLETE'], self.stack_name, self.stack_user)
def test_create_stack_during_launch(self): task = LaunchStackTask() mock_heat_client = Mock() mock_heat_client.stacks.get.side_effect = [ HTTPNotFound, self.stacks['CREATE_IN_PROGRESS'], self.stacks['CREATE_IN_PROGRESS'], self.stacks['CREATE_COMPLETE'] ] mock_heat_client.stacks.create.return_value = { 'stack': {'id': self.stack_name} } mock_verify_stack = Mock(return_value=('VERIFY_COMPLETE', None, self.stack_ip)) with patch.multiple(task, get_heat_client=Mock(return_value=mock_heat_client), verify_stack=mock_verify_stack ): res = task.run( self.configuration, self.stack_name, self.stack_template, self.stack_user, False ) assert res['status'] == 'CREATE_COMPLETE' mock_heat_client.stacks.create.assert_called_with( stack_name=self.stack_name, template=self.stack_template ) mock_verify_stack.assert_called_with( self.configuration, self.stacks['CREATE_COMPLETE'], self.stack_name, self.stack_user )
def test_dont_wait_forever_for_creation_and_delete_during_launch(self): task = LaunchStackTask() mock_heat_client = Mock() mock_heat_client.stacks.get.side_effect = [ HTTPNotFound, self.stacks['CREATE_IN_PROGRESS'], self.stacks['CREATE_IN_PROGRESS'], self.stacks['CREATE_IN_PROGRESS'], self.stacks['CREATE_IN_PROGRESS'], self.stacks['CREATE_IN_PROGRESS'] ] mock_heat_client.stacks.create.return_value = { 'stack': { 'id': self.stack_name } } with patch.multiple( task, sleep=0, retries=3, get_heat_client=Mock(return_value=mock_heat_client)): res = task.run(self.stack_name, self.stack_template, self.stack_user, self.auth_url) assert res['status'] == 'CREATE_FAILED' mock_heat_client.stacks.delete.assert_called_with( stack_id=self.stacks['CREATE_IN_PROGRESS'].id)
def test_resume_suspending_stack_during_launch(self): task = LaunchStackTask() mock_heat_client = Mock() mock_heat_client.stacks.get.side_effect = [ self.stacks['SUSPEND_IN_PROGRESS'], self.stacks['SUSPEND_IN_PROGRESS'], self.stacks['SUSPEND_COMPLETE'], self.stacks['RESUME_IN_PROGRESS'], self.stacks['RESUME_IN_PROGRESS'], self.stacks['RESUME_COMPLETE'] ] mock_return_value = { "ip": self.stack_ip, "key": self.stack_key, "password": self.stack_password } mock_check_stack = Mock(return_value=mock_return_value) with patch.multiple( task, get_heat_client=Mock( return_value=mock_heat_client), # noqa: E501 check_stack=mock_check_stack): stack_template = 'bogus_stack_template' res = task.run(self.configuration, self.run_name, self.stack_name, stack_template, self.stack_user, False) self.assertEqual(res['status'], 'RESUME_COMPLETE') mock_heat_client.actions.resume.assert_called_with( stack_id=self.stacks['SUSPEND_COMPLETE'].id) mock_check_stack.assert_called()
def test_resume_suspending_stack_during_launch(self): task = LaunchStackTask() mock_heat_client = Mock() mock_heat_client.stacks.get.side_effect = [ self.stacks['SUSPEND_IN_PROGRESS'], self.stacks['SUSPEND_IN_PROGRESS'], self.stacks['SUSPEND_COMPLETE'], self.stacks['RESUME_IN_PROGRESS'], self.stacks['RESUME_IN_PROGRESS'], self.stacks['RESUME_COMPLETE'] ] mock_verify_stack = Mock(return_value=('VERIFY_COMPLETE', None, self.stack_ip)) with patch.multiple(task, get_heat_client=Mock(return_value=mock_heat_client), verify_stack=mock_verify_stack ): res = task.run( self.configuration, self.stack_name, self.stack_template, self.stack_user, False ) assert res['status'] == 'RESUME_COMPLETE' mock_heat_client.actions.resume.assert_called_with( stack_id=self.stacks['SUSPEND_COMPLETE'].id ) mock_verify_stack.assert_called_with( self.configuration, self.stacks['RESUME_COMPLETE'], self.stack_name, self.stack_user )
def test_dont_wait_forever_for_creation_and_delete_during_launch(self): task = LaunchStackTask() mock_heat_client = Mock() mock_heat_client.stacks.get.side_effect = [ HTTPNotFound, self.stacks['CREATE_IN_PROGRESS'], self.stacks['CREATE_IN_PROGRESS'], self.stacks['CREATE_IN_PROGRESS'], self.stacks['CREATE_IN_PROGRESS'], self.stacks['CREATE_IN_PROGRESS'] ] mock_heat_client.stacks.create.return_value = { 'stack': {'id': self.stack_name} } with patch.multiple(task, get_heat_client=Mock(return_value=mock_heat_client) ): self.configuration['task_timeouts']['retries'] = 3 res = task.run( self.configuration, self.stack_name, self.stack_template, self.stack_user, False ) assert res['status'] == 'CREATE_FAILED' mock_heat_client.stacks.delete.assert_called_with( stack_id=self.stacks['CREATE_IN_PROGRESS'].id )
def test_dont_reset_new_stack_during_launch(self): task = LaunchStackTask() mock_heat_client = Mock() mock_heat_client.stacks.get.side_effect = [ HTTPNotFound, self.stacks['CREATE_IN_PROGRESS'], self.stacks['CREATE_COMPLETE'] ] mock_heat_client.stacks.create.return_value = { 'stack': { 'id': self.stack_name } } mock_return_value = { "ip": self.stack_ip, "key": self.stack_key, "password": self.stack_password } mock_check_stack = Mock(return_value=mock_return_value) with patch.multiple( task, get_heat_client=Mock( return_value=mock_heat_client), # noqa: E501 check_stack=mock_check_stack): stack_template = 'bogus_stack_template' res = task.run(self.configuration, self.run_name, self.stack_name, stack_template, self.stack_user, True) mock_heat_client.stacks.delete.assert_not_called() mock_heat_client.stacks.create.assert_called_with( parameters={'run': self.run_name}, stack_name=self.stack_name, template=stack_template) mock_check_stack.assert_called() self.assertEqual(res['status'], 'CREATE_COMPLETE')
def test_create_stack_during_launch(self): task = LaunchStackTask() mock_heat_client = Mock() mock_heat_client.stacks.get.side_effect = [ HTTPNotFound, self.stacks['CREATE_IN_PROGRESS'], self.stacks['CREATE_IN_PROGRESS'], self.stacks['CREATE_COMPLETE'] ] mock_heat_client.stacks.create.return_value = { 'stack': { 'id': self.stack_name } } mock_wait_for_ping = Mock() mock_ssh = Mock() setup_ssh_retval = (mock_ssh, "bogus_pkey") with patch.multiple( task, get_heat_client=Mock( return_value=mock_heat_client), # noqa: E501 wait_for_ping=mock_wait_for_ping, setup_ssh=Mock(return_value=setup_ssh_retval)): stack_template = 'bogus_stack_template' res = task.run(self.configuration, self.run_name, self.stack_name, stack_template, self.stack_user, False) self.assertEqual(res['status'], 'CREATE_COMPLETE') self.assertNotEqual(res['error_msg'], None) mock_heat_client.stacks.create.assert_called_with( parameters={'run': self.run_name}, stack_name=self.stack_name, template=stack_template) mock_wait_for_ping.assert_called() mock_ssh.connect.assert_called()
def test_exit_resume_failed_exit_status_during_launch(self): task = LaunchStackTask() mock_heat_client = Mock() mock_heat_client.stacks.get.side_effect = [ self.stacks['SUSPEND_COMPLETE'], self.stacks['RESUME_IN_PROGRESS'], self.stacks['RESUME_IN_PROGRESS'], self.stacks['RESUME_FAILED'] ] with patch.multiple( task, sleep=0, get_heat_client=Mock(return_value=mock_heat_client)): res = task.run(self.stack_name, self.stack_template, self.stack_user, self.auth_url) assert res['status'] == 'RESUME_FAILED'
def test_exit_resume_failed_exit_status_during_launch(self): task = LaunchStackTask() mock_heat_client = Mock() mock_heat_client.stacks.get.side_effect = [ self.stacks['SUSPEND_COMPLETE'], self.stacks['RESUME_IN_PROGRESS'], self.stacks['RESUME_IN_PROGRESS'], self.stacks['RESUME_FAILED']] with patch.multiple(task, sleep=0, get_heat_client=Mock(return_value=mock_heat_client)): res = task.run(self.stack_name, self.stack_template, self.stack_user, self.auth_url) assert res['status'] == 'RESUME_FAILED'
def test_exit_resume_failed_exit_status_during_launch(self): task = LaunchStackTask() mock_heat_client = Mock() mock_heat_client.stacks.get.side_effect = [ self.stacks['SUSPEND_COMPLETE'], self.stacks['RESUME_IN_PROGRESS'], self.stacks['RESUME_IN_PROGRESS'], self.stacks['RESUME_FAILED'] ] with patch.multiple(task, get_heat_client=Mock( return_value=mock_heat_client)): # noqa: E501 stack_template = 'bogus_stack_template' res = task.run(self.configuration, self.run_name, self.stack_name, stack_template, self.stack_user, False) self.assertEqual(res['status'], 'RESUME_FAILED')
def test_delete_stack_on_create_failed_during_launch(self): task = LaunchStackTask() mock_heat_client = Mock() mock_heat_client.stacks.get.side_effect = [ HTTPNotFound, self.stacks['CREATE_IN_PROGRESS'], self.stacks['CREATE_FAILED']] mock_heat_client.stacks.create.return_value = {'stack': {'id': self.stack_name}} with patch.multiple(task, sleep=0, get_heat_client=Mock(return_value=mock_heat_client)): res = task.run(self.stack_name, self.stack_template, self.stack_user, self.auth_url) assert res['status'] == 'CREATE_FAILED' mock_heat_client.stacks.delete.assert_called_with(stack_id=self.stacks['CREATE_FAILED'].id)
def test_dont_wait_forever_for_suspension_during_launch(self): task = LaunchStackTask() mock_heat_client = Mock() mock_heat_client.stacks.get.side_effect = [ self.stacks['SUSPEND_IN_PROGRESS'], self.stacks['SUSPEND_IN_PROGRESS'], SoftTimeLimitExceeded ] with patch.multiple(task, get_heat_client=Mock( return_value=mock_heat_client)): # noqa: E501 stack_template = 'bogus_stack_template' res = task.run(self.configuration, self.run_name, self.stack_name, stack_template, self.stack_user, False) self.assertEqual(res['status'], 'LAUNCH_TIMEOUT') mock_heat_client.stacks.delete.assert_not_called()
def test_dont_wait_forever_for_suspension_and_delete_during_launch(self): task = LaunchStackTask() mock_heat_client = Mock() mock_heat_client.stacks.get.side_effect = [ self.stacks['SUSPEND_IN_PROGRESS'], self.stacks['SUSPEND_IN_PROGRESS'], self.stacks['SUSPEND_IN_PROGRESS'], self.stacks['SUSPEND_IN_PROGRESS'], self.stacks['SUSPEND_IN_PROGRESS']] with patch.multiple(task, sleep=0, retries=3, get_heat_client=Mock(return_value=mock_heat_client)): res = task.run(self.stack_name, self.stack_template, self.stack_user, self.auth_url) assert res['status'] == 'CREATE_FAILED' mock_heat_client.stacks.delete.assert_called_with(stack_id=self.stacks['SUSPEND_IN_PROGRESS'].id)
def test_dont_wait_forever_for_ssh(self): task = LaunchStackTask() mock_heat_client = Mock() mock_heat_client.stacks.get.return_value = self.stacks[ 'CREATE_COMPLETE'] # noqa: E501 mock_wait_for_ping = Mock() mock_ssh = Mock() mock_ssh.connect.side_effect = SoftTimeLimitExceeded setup_ssh_retval = (mock_ssh, "bogus_pkey") with patch.multiple( task, get_heat_client=Mock( return_value=mock_heat_client), # noqa: E501 wait_for_ping=mock_wait_for_ping, setup_ssh=Mock(return_value=setup_ssh_retval)): stack_template = 'bogus_stack_template' res = task.run(self.configuration, self.run_name, self.stack_name, stack_template, self.stack_user, False) self.assertEqual(res['status'], 'LAUNCH_TIMEOUT')
def test_ssh_bombs_out(self): task = LaunchStackTask() mock_heat_client = Mock() mock_heat_client.stacks.get.return_value = self.stacks[ 'CREATE_COMPLETE'] # noqa: E501 mock_wait_for_ping = Mock() mock_ssh = Mock() mock_ssh.connect.side_effect = Exception() setup_ssh_retval = (mock_ssh, "bogus_pkey") with patch.multiple( task, get_heat_client=Mock( return_value=mock_heat_client), # noqa: E501 wait_for_ping=mock_wait_for_ping, setup_ssh=Mock(return_value=setup_ssh_retval)): stack_template = 'bogus_stack_template' res = task.run(self.configuration, self.run_name, self.stack_name, stack_template, self.stack_user, False) self.assertEqual(res['status'], 'CREATE_FAILED')
def test_delete_stack_on_create_failed_during_launch(self): task = LaunchStackTask() mock_heat_client = Mock() mock_heat_client.stacks.get.side_effect = [ HTTPNotFound, self.stacks['CREATE_IN_PROGRESS'], self.stacks['CREATE_FAILED'] ] mock_heat_client.stacks.create.return_value = { 'stack': { 'id': self.stack_name } } with patch.multiple(task, get_heat_client=Mock( return_value=mock_heat_client)): # noqa: E501 stack_template = 'bogus_stack_template' res = task.run(self.configuration, self.run_name, self.stack_name, stack_template, self.stack_user, False) self.assertEqual(res['status'], 'CREATE_FAILED') mock_heat_client.stacks.delete.assert_called_with( stack_id=self.stack_name)
def test_dont_wait_forever_for_creation_and_delete_during_launch(self): task = LaunchStackTask() mock_heat_client = Mock() mock_heat_client.stacks.get.side_effect = [ HTTPNotFound, self.stacks['CREATE_IN_PROGRESS'], self.stacks['CREATE_IN_PROGRESS'], SoftTimeLimitExceeded ] mock_heat_client.stacks.create.return_value = { 'stack': { 'id': self.stack_name } } with patch.multiple(task, get_heat_client=Mock( return_value=mock_heat_client)): # noqa: E501 stack_template = 'bogus_stack_template' res = task.run(self.configuration, self.run_name, self.stack_name, stack_template, self.stack_user, False) mock_heat_client.stacks.delete.assert_called_with( stack_id=self.stack_name) self.assertEqual(res['status'], 'LAUNCH_TIMEOUT')
def test_resume_suspended_stack_during_launch(self): task = LaunchStackTask() mock_heat_client = Mock() mock_heat_client.stacks.get.side_effect = [ self.stacks['SUSPEND_COMPLETE'], self.stacks['RESUME_IN_PROGRESS'], self.stacks['RESUME_IN_PROGRESS'], self.stacks['RESUME_COMPLETE'] ] mock_verify_stack = Mock(return_value=('RESUME_COMPLETE', None, self.stack_ip)) with patch.multiple( task, sleep=0, get_heat_client=Mock(return_value=mock_heat_client), verify_stack=mock_verify_stack): res = task.run(self.stack_name, self.stack_template, self.stack_user, self.auth_url) assert res['status'] == 'RESUME_COMPLETE' mock_heat_client.actions.resume.assert_called_with( stack_id=self.stacks['SUSPEND_COMPLETE'].id) mock_verify_stack.assert_called_with( self.stacks['RESUME_COMPLETE'], self.stack_name, self.stack_user)
def test_dont_wait_forever_for_suspension_during_launch(self): task = LaunchStackTask() mock_heat_client = Mock() mock_heat_client.stacks.get.side_effect = [ self.stacks['SUSPEND_IN_PROGRESS'], self.stacks['SUSPEND_IN_PROGRESS'], self.stacks['SUSPEND_IN_PROGRESS'], self.stacks['SUSPEND_IN_PROGRESS'], self.stacks['SUSPEND_IN_PROGRESS'] ] with patch.multiple(task, get_heat_client=Mock(return_value=mock_heat_client) ): self.configuration['task_timeouts']['retries'] = 3 res = task.run( self.configuration, self.stack_name, self.stack_template, self.stack_user, False ) assert res['status'] == 'SUSPEND_FAILED' mock_heat_client.stacks.delete.assert_not_called()