示例#1
0
 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)
示例#2
0
 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
         )
示例#3
0
 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)
示例#4
0
 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()
示例#5
0
 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
         )
示例#6
0
 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
         )
示例#7
0
 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')
示例#8
0
 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()
示例#9
0
 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'
示例#10
0
 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'
示例#11
0
 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')
示例#12
0
 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)
示例#13
0
 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()
示例#14
0
 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)
示例#15
0
 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')
示例#16
0
 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')
示例#17
0
 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)
示例#18
0
 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')
示例#19
0
 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)
示例#20
0
 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()