Ejemplo n.º 1
0
 def test_execute_tasks_task_wait(self, _add_tasks_mock, _get_task_mock,
         _get_results_mock):
     """Execute tasks waiting for a task to finish."""
     task_1 = Mock()
     task_1.uuid = 'test_task_1'
     task_2 = Mock()
     task_2.uuid = 'test_task_2'
     _add_tasks_mock.return_value = [task_1, task_2]
     task_3 = Mock()
     task_3.state = 'success'
     task_4 = Mock()
     task_4.state = 'started'
     task_5 = Mock()
     task_5.state = 'success'
     _get_task_mock.side_effect = [task_3, task_4, task_5]
     result1 = Mock()
     result1.tag = json.dumps('test_result_1')
     result2 = Mock()
     result2.tag = json.dumps('test_result_2')
     _get_results_mock.side_effect = [[result1], [result2]]
     tasks = [snowfloat.task.Task(
                 operation='test_operation_1',
                 task_filter={'layer_uuid_exact': 'test_layer_1'}),
              snowfloat.task.Task(
                 operation='test_operation_2',
                 task_filter={'layer_uuid_exact': 'test_layer_2'})]
     res = self.client.execute_tasks(tasks, interval=0.1)
     self.assertListEqual(res, [['test_result_1',], ['test_result_2',]])
     self.execute_tasks_add_tasks_helper(_add_tasks_mock)
     self.assertEqual(_get_task_mock.call_args_list,
         [call(task_1.uuid), call(task_2.uuid), call(task_2.uuid)])
     self.assertEqual(_get_results_mock.call_args_list,
         [call(task_1.uuid), call(task_2.uuid)])
Ejemplo n.º 2
0
    def fake_action_runs(self):
        mock_unknown_machine = Mock(autospec=True)
        mock_ok_machine = Mock(autospec=True)

        mock_unknown_machine.state = ActionRun.UNKNOWN
        mock_ok_machine.state = ActionRun.SUCCEEDED
        self.action_runs = [
            SSHActionRun(
                job_run_id="test.unknown",
                name="test.unknown",
                node=Mock(),
                machine=mock_unknown_machine,
            ),
            SSHActionRun(
                job_run_id="test.succeeded",
                name="test.succeeded",
                node=Mock(),
                machine=mock_ok_machine,
            ),
            MesosActionRun(
                job_run_id="test.succeeded",
                name="test.succeeded",
                node=Mock(),
                machine=mock_ok_machine,
            ),
        ]
Ejemplo n.º 3
0
 def test_execute_tasks(self, _add_tasks_mock, _get_task_mock,
     _get_results_mock):
     """Execute asynchronous tasks."""
     task_1 = Mock()
     task_1.uuid = 'test_task_1'
     task_2 = Mock()
     task_2.uuid = 'test_task_2'
     _add_tasks_mock.return_value = [task_1, task_2]
     task_3 = Mock()
     task_3.state = 'success'
     task_4 = Mock()
     task_4.state = 'success'
     _get_task_mock.side_effect = [task_3, task_4]
     result1 = Mock()
     result1.tag = json.dumps('test_result_1')
     result2 = Mock()
     result2.tag = json.dumps('test_result_2')
     _get_results_mock.side_effect = [[result1], [result2]]
     tasks = [snowfloat.task.Task(
                 operation='test_operation_1',
                 task_filter={'layer_uuid_exact': 'test_layer_1'}),
              snowfloat.task.Task(
                 operation='test_operation_2',
                 task_filter={'layer_uuid_exact': 'test_layer_2'})]
     res = self.client.execute_tasks(tasks)
     self.assertListEqual(res, [['test_result_1',], ['test_result_2',]])
     self.execute_tasks_add_tasks_helper(_add_tasks_mock)
Ejemplo n.º 4
0
 def test_num_pad_button(self):
     microwave.NumPadButton.__bases__ = (MockWidget, )
     timer = Mock(total="0000")
     micro = Mock(timer=timer)
     number_pad = Mock(master=micro)
     # Cooking state & press_num() => No time change
     micro.state = microwave.CookingState(micro)
     button9 = microwave.NumPadButton(number_pad, text="9")
     button9["command"]()
     self.assertEqual("0000", button9.master.master.timer.total)
     # Stopped state, timer == '0000' & press_num() '9' => timer == '0009'
     micro.state = microwave.StoppedState(micro)
     button9["command"]()
     self.assertEqual("0009", button9.master.master.timer.total)
     # Stopped state, timer == '0009' & press_num() '8' => timer == '0098'
     button8 = microwave.NumPadButton(number_pad, text="8")
     button8["command"]()
     self.assertEqual("0098", button8.master.master.timer.total)
     # Stopped state, timer == '0098' & press_num() '7' => timer == '0987'
     button7 = microwave.NumPadButton(number_pad, text="7")
     button7["command"]()
     self.assertEqual("0987", button7.master.master.timer.total)
     # Stopped state, timer == '0987' & press_num() '6' => timer == '9876'
     button6 = microwave.NumPadButton(number_pad, text="6")
     button6["command"]()
     self.assertEqual("9876", button6.master.master.timer.total)
     # Stopped state, timer == '9876' & press_num() '5' => No time change
     button5 = microwave.NumPadButton(number_pad, text="5")
     button5["command"]()
     self.assertEqual("9876", button5.master.master.timer.total)
Ejemplo n.º 5
0
 def test_execute_tasks_task_failure(self, _add_tasks_mock, _get_task_mock,
         _get_results_mock):
     """Execute tasks with a task failure."""
     task_1 = Mock()
     task_1.uuid = 'test_task_1'
     task_2 = Mock()
     task_2.uuid = 'test_task_2'
     _add_tasks_mock.return_value = [task_1, task_2]
     task_3 = Mock()
     task_3.state = 'success'
     task_4 = Mock()
     task_4.state = 'failure'
     task_4.reason = 'test_reason'
     _get_task_mock.side_effect = [task_3, task_4]
     result1 = Mock()
     result1.tag = json.dumps('test_result_1')
     result2 = Mock()
     result2.tag = json.dumps('test_result_2')
     _get_results_mock.side_effect = [[result1], [result2]]
     tasks = [snowfloat.task.Task(
                 operation='test_operation_1',
                 task_filter={'layer_uuid_exact': 'test_layer_1'}),
              snowfloat.task.Task(
                 operation='test_operation_2',
                 task_filter={'layer_uuid_exact': 'test_layer_2'})]
     res = self.client.execute_tasks(tasks)
     self.assertListEqual(res, [['test_result_1',],
         {'error': 'test_reason'}])
     self.execute_tasks_add_tasks_helper(_add_tasks_mock)
     self.assertEqual(_get_task_mock.call_args_list,
         [call(task_1.uuid), call(task_2.uuid)])
     self.assertEqual(_get_results_mock.call_args_list,
         [call(task_1.uuid),])
Ejemplo n.º 6
0
 def test_num_pad_button(self):
     microwave.NumPadButton.__bases__ = (MockWidget,)
     timer = Mock(total="0000")
     micro = Mock(timer=timer)
     number_pad = Mock(master=micro)
     # Cooking state & press_num() => No time change
     micro.state = microwave.CookingState(micro)
     button9 = microwave.NumPadButton(number_pad, text="9")
     button9["command"]()
     self.assertEqual("0000", button9.master.master.timer.total)
     # Stopped state, timer == '0000' & press_num() '9' => timer == '0009'
     micro.state = microwave.StoppedState(micro)
     button9["command"]()
     self.assertEqual("0009", button9.master.master.timer.total)
     # Stopped state, timer == '0009' & press_num() '8' => timer == '0098'
     button8 = microwave.NumPadButton(number_pad, text="8")
     button8["command"]()
     self.assertEqual("0098", button8.master.master.timer.total)
     # Stopped state, timer == '0098' & press_num() '7' => timer == '0987'
     button7 = microwave.NumPadButton(number_pad, text="7")
     button7["command"]()
     self.assertEqual("0987", button7.master.master.timer.total)
     # Stopped state, timer == '0987' & press_num() '6' => timer == '9876'
     button6 = microwave.NumPadButton(number_pad, text="6")
     button6["command"]()
     self.assertEqual("9876", button6.master.master.timer.total)
     # Stopped state, timer == '9876' & press_num() '5' => No time change
     button5 = microwave.NumPadButton(number_pad, text="5")
     button5["command"]()
     self.assertEqual("9876", button5.master.master.timer.total)
Ejemplo n.º 7
0
    def test_we_capture_the_checkurl_exception_and_return_false(self, mock_landlord, mock_ec2):
        properties = {'region': 'myRegion', 'environment': 'STAGE', 'domain': 'this.is.awesome'}
        project = {'name': 'MyProject', 'version': 'v34', 'type': 'play2'}
        instances_ids = ['blah']

        mock_landlord.Tenant = StubNameLandlord
        mock_connection = Mock()
        mock_ec2.connect_to_region.return_value = mock_connection

        instance1 = Mock()
        instance1.id = 'i-938372'
        instance1.ip_address = '192.1.11.1'
        instance1.state = 'running'
        instance1.launch_time = datetime.date.today().isoformat()
        instance1.tags = {'Name': 'STAGE-Instance-1', 'Project': 'Instance', 'Version': 'v43'}

        instance2 = Mock()
        instance2.id = 'i-542211'
        instance2.state = 'stopped'
        instance2.ip_address = None
        instance2.launch_time = datetime.date.today().isoformat()
        instance2.tags = {'Name': 'STAGE-Instance-2', 'Project': 'Instance', 'Version': 'v43'}

        mock_connection.get_only_instances.return_value = [instance1, instance2]

        real_function = ec2.check_url

        ec2.check_url = Mock(side_effect=[Exception('BOOM!','I have created an instance and you are wasting money... muahahaha')])

        result = ec2.is_running(instances_ids, project)

        self.assertEquals(False, result)

        ec2.check_url = real_function
Ejemplo n.º 8
0
    def test_find_all_unresolved_node_instances(self):
        _ctx = self._gen_ctx()
        a_instance = Mock()
        a_instance.id = u"a_id"
        a_instance.state = u"started"
        c_instance = Mock()
        c_instance.id = u"c_id"
        c_instance.state = u"starting"
        a_node = Mock()
        a_node.id = u"a_node_id"
        a_node.instances = [a_instance, c_instance]
        b_instance = Mock()
        b_instance.id = u"b_id"
        b_instance.state = u"configuring"
        b_node = Mock()
        b_node.instances = [b_instance]
        _ctx.nodes = [a_node, b_node]
        unresolved_nodes = workflows._find_all_unresolved_node_instances(
            _ctx, node_ids=[], node_instance_ids=[], type_names=[])
        self.assertListEqual(unresolved_nodes, [c_instance, b_instance])

        unresolved_nodes = workflows._find_all_unresolved_node_instances(
            _ctx, node_ids=[], node_instance_ids=[u"c_id"], type_names=[])
        self.assertListEqual(unresolved_nodes, [c_instance])

        unresolved_nodes = workflows._find_all_unresolved_node_instances(
            _ctx, node_ids=[u"a_node_id"], node_instance_ids=[], type_names=[])
        self.assertListEqual(unresolved_nodes, [c_instance])
Ejemplo n.º 9
0
  def testGetSuggestedInstancesTwoDifferentSize(self, getEC2InstancesMock):
    regionMock = Mock(spec="boto.ec2.region.Region")
    regionMock.name = "us-west-2"
    # Instance 1
    instanceMock1 = Mock(spec="boto.ec2.instance.Instance")
    instanceMock1.state = "running"
    instanceMock1.instance_type = "m3.large"
    instanceMock1.launch_time = "2014-05-06T15:17:33.324Z"
    instanceMock1.region = regionMock
    instanceMock1.id = "testId1"
    instanceMock1.tags = {"Name": "testName1"}
    # Instance 2
    instanceMock2 = Mock(spec="boto.ec2.instance.Instance")
    instanceMock2.state = "running"
    instanceMock2.instance_type = "m3.xlarge"
    instanceMock2.launch_time = "2014-05-06T15:18:33.324Z"
    instanceMock2.region = regionMock
    instanceMock2.id = "testId2"
    instanceMock2.tags = {"Name": "testName2"}
    getEC2InstancesMock.return_value = [
        instanceMock1,
        instanceMock2,
    ]

    suggestions = ec2_utils.getSuggestedInstances(regionMock.name)
    self.assertIsInstance(suggestions, types.GeneratorType)
    suggestions = list(suggestions)

    self.assertSequenceEqual(suggestions, [
        {"id": "testId2", "name": "testName2", "namespace": "AWS/EC2",
         "region": regionMock.name},
        {"id": "testId1", "name": "testName1", "namespace": "AWS/EC2",
         "region": regionMock.name},
    ])
    getEC2InstancesMock.assert_call_once_with(regionMock.name)
Ejemplo n.º 10
0
    def test_we_can_get_all_instances(self, mock_landlord, mock_ec2):
        persistence.save('Instance1', 'v43')
        persistence.save('Instance2', 'v43')
        mock_landlord.Tenant = StubLandlord
        mock_connection = Mock()
        mock_ec2.connect_to_region.return_value = mock_connection

        instance1 = Mock()
        instance1.id = 'i-938372'
        instance1.dns_name = '192.1.11.1.dnsname'
        instance1.ip_address = '192.1.11.1'
        instance1.state = 'running'
        instance1.tags = {'Name': 'STAGE-Instance-1', 'Project': 'Instance', 'Version': 'v43', 'AutoStopped': 'True'}
        instance1.launch_time = datetime.date.today().isoformat()
        instance1.image_id = 'ami-192812'

        instance2 = Mock()
        instance2.id = 'i-542211'
        instance2.dns_name = '192.5.5.5.dnsname'
        instance2.ip_address = '192.5.5.5'
        instance2.state = 'stopped'
        instance2.tags = {'Name': 'Instance2', 'Project': 'Instance', 'Version': 'v43'}
        instance2.launch_time = datetime.date.today().isoformat()
        instance2.image_id = 'ami-237829'

        mock_connection.get_only_instances.return_value = [instance1, instance2]

        instances = ec2.get_all_instances()

        mock_ec2.connect_to_region.assert_called_with('eu-west-1', aws_access_key_id='aws.id',
                                                      aws_secret_access_key='aws.secret')
        mock_connection.get_only_instances.assert_called_with(filters={"tag:Deployer": "igor"})
        self.assertEquals(len(instances), 2)
        self.assertEquals(instances[0]['name'], 'Instance-1')
        self.assertEquals(instances[0]['version'], 'v43')
        self.assertEquals(instances[0]['project'], 'Instance')
        self.assertEquals(instances[0]['date'], datetime.date.today().isoformat())
        self.assertEquals(instances[0]['ip'], '192.1.11.1')
        self.assertEquals(instances[0]['status'], 'running')
        self.assertEquals(instances[0]['autoStopped'], 'True')

        self.assertEquals(instances[1]['name'], 'Instance2')
        self.assertEquals(instances[1]['version'], 'v43')
        self.assertEquals(instances[1]['project'], 'Instance')
        self.assertEquals(instances[1]['date'], datetime.date.today().isoformat())
        self.assertEquals(instances[1]['ip'], '192.5.5.5')
        self.assertEquals(instances[1]['status'], 'stopped')
        self.assertEquals(instances[1]['ami'], 'ami-237829')
        self.assertEquals(instances[1]['autoStopped'], 'NA')
Ejemplo n.º 11
0
    def test_delete_blackhole_routes(self):
        # prepare
        active_route = Mock()
        active_route.state = 'active'
        blackhole_route = Mock()
        blackhole_route.state = 'blackhole'

        route_table = Mock()
        route_table.routes = [active_route, blackhole_route]

        # act
        self.route_table_service.delete_blackhole_routes(route_table=route_table)

        # assert
        self.assertTrue(blackhole_route.delete.called)
        self.assertFalse(active_route.delete.called)
Ejemplo n.º 12
0
    def test_success(self):
        """
        Connect a stream via a circuit
        """
        reactor = Mock()
        torstate = Mock()
        target = Mock()
        target.connect = Mock(return_value=defer.succeed('fake proto'))
        circ = Mock()
        circ.state = 'NEW'
        src_addr = Mock()
        src_addr.host = 'host'
        src_addr.port = 1234
        target._get_address = Mock(return_value=defer.succeed(src_addr))
        stream = Mock()
        stream.source_port = 1234
        stream.source_addr = 'host'

        # okay, so we fire up our circuit-endpoint with mostly mocked
        # things, and a circuit that's already in 'FAILED' state.
        ep = TorCircuitEndpoint(reactor, torstate, circ, target)

        # should get a Failure from the connect()
        d = ep.connect(Mock())
        attacher = yield _get_circuit_attacher(reactor, torstate)
        yield attacher.attach_stream(stream, [circ])
        proto = yield d
        self.assertEqual(proto, 'fake proto')
Ejemplo n.º 13
0
    def test_create_deployment_parameters_single_subnet(self):
        image = Mock()
        image.state = 'available'
        ec2_session = Mock()
        ec2_session.Image = Mock(return_value=image)
        ami_model = Mock()
        ami_model.aws_ami_id = 'asd'
        ami_model.storage_size = '0'
        ami_model.iam_role = ""
        network_actions = None
        vpc = Mock()
        self.deploy_operation._get_block_device_mappings = Mock()

        aws_model = self.deploy_operation._create_deployment_parameters(ec2_session=ec2_session,
                                                                        aws_ec2_resource_model=self.ec2_datamodel,
                                                                        ami_deployment_model=ami_model,
                                                                        network_actions=network_actions,
                                                                        vpc=vpc,
                                                                        security_group=None,
                                                                        key_pair='keypair',
                                                                        reservation=Mock(),
                                                                        network_config_results=MagicMock(),
                                                                        logger=self.logger)

        self.assertEquals(aws_model.min_count, 1)
        self.assertEquals(aws_model.max_count, 1)
        self.assertEquals(aws_model.aws_key, 'keypair')
        self.assertTrue(len(aws_model.security_group_ids) == 1)
        self.assertTrue(len(aws_model.network_interfaces) == 1)
Ejemplo n.º 14
0
    def test_circuit_stream_failure(self):
        """
        If the stream-attach fails the error propagates
        """
        reactor = Mock()
        torstate = Mock()
        target = Mock()
        target.connect = Mock(return_value=defer.succeed(None))
        circ = Mock()
        circ.state = 'FAILED'
        src_addr = Mock()
        src_addr.host = 'host'
        src_addr.port = 1234
        target._get_address = Mock(return_value=defer.succeed(src_addr))
        stream = Mock()
        stream.source_port = 1234
        stream.source_addr = 'host'

        # okay, so we fire up our circuit-endpoint with mostly mocked
        # things, and a circuit that's already in 'FAILED' state.
        ep = TorCircuitEndpoint(reactor, torstate, circ, target)

        # should get a Failure from the connect()
        d = ep.connect(Mock())
        attacher = yield _get_circuit_attacher(reactor, Mock())
        attacher.attach_stream_failure(stream, RuntimeError("a bad thing"))
        try:
            yield d
            self.fail("Should get exception")
        except RuntimeError as e:
            self.assertEqual("a bad thing", str(e))
 async def mock_connect(self):
     mconnect = Mock(spec=websockets.protocol.WebSocketCommonProtocol)
     mconnect.state = 1
     for f in self.mocks:
         setattr(mconnect, f, asyncio.coroutine(self.mocks[f]))
     self.mock_connect = mconnect
     return asyncio.coroutine(mconnect)
Ejemplo n.º 16
0
    def test_create_deployment_parameters_single_subnet(self):
        image = Mock()
        image.state = 'available'
        ec2_session = Mock()
        ec2_session.Image = Mock(return_value=image)
        ami_model = Mock()
        ami_model.aws_ami_id = 'asd'
        ami_model.storage_size = '0'
        ami_model.iam_role = ""
        network_actions = None
        vpc = Mock()
        self.deploy_operation._get_block_device_mappings = Mock()

        aws_model = self.deploy_operation._create_deployment_parameters(ec2_session=ec2_session,
                                                                        aws_ec2_resource_model=self.ec2_datamodel,
                                                                        ami_deployment_model=ami_model,
                                                                        network_actions=network_actions,
                                                                        vpc=vpc,
                                                                        security_group=None,
                                                                        key_pair='keypair',
                                                                        reservation=Mock(),
                                                                        network_config_results=MagicMock(),
                                                                        logger=self.logger)

        self.assertEquals(aws_model.min_count, 1)
        self.assertEquals(aws_model.max_count, 1)
        self.assertEquals(aws_model.aws_key, 'keypair')
        self.assertTrue(len(aws_model.security_group_ids) == 1)
        self.assertTrue(len(aws_model.network_interfaces) == 1)
Ejemplo n.º 17
0
 def setUp(self):
     self.coreMock = mopidy.core.Core(None, [])
     self.buttonPressEvent = lib.Event()
     playback = Mock()
     playback.mute = self.WithGet(False)
     playback.volume = self.WithGet(50)
     playback.state = self.WithGet(mopidy.core.PlaybackState.STOPPED)
     self.coreMock.playback = playback
Ejemplo n.º 18
0
    def test_check_combined_status_commit(self, sha, statuses,
                                          statuses_returned, state,
                                          success_expected, use_statuses):
        if use_statuses:
            mock_combined_status = Mock(spec=CommitCombinedStatus)
            mock_combined_status.statuses = [
                Mock(spec=CommitStatus, id=i, state=state) for i in statuses
            ]
            mock_combined_status.state = state

            commit_mock = Mock(spec=Commit, url="some.fake.repo/")
            commit_mock.get_combined_status.return_value = mock_combined_status
            self.repo_mock.get_commit.return_value = commit_mock
            commit_mock._requester = Mock()  # pylint: disable=protected-access
            # pylint: disable=protected-access
            commit_mock._requester.requestJsonAndCheck.return_value = ({}, {
                'check_suites': []
            })
        else:
            mock_combined_status = Mock(spec=CommitCombinedStatus)
            mock_combined_status.statuses = []
            mock_combined_status.state = None
            mock_combined_status.url = None

            commit_mock = Mock(spec=Commit, url="some.fake.repo/")
            commit_mock.get_combined_status.return_value = mock_combined_status
            self.repo_mock.get_commit.return_value = commit_mock
            commit_mock._requester = Mock()  # pylint: disable=protected-access
            # pylint: disable=protected-access
            commit_mock._requester.requestJsonAndCheck.return_value = ({}, {
                'check_suites': [{
                    'app': {
                        'name': 'App {}'.format(i)
                    },
                    'conclusion': state,
                    'url': 'some.fake.repo'
                } for i in statuses]
            })

        successful, statuses = self.api.check_combined_status_commit(sha)

        assert successful == success_expected
        assert isinstance(statuses, dict)
        assert len(statuses) == statuses_returned
        commit_mock.get_combined_status.assert_called()
        self.repo_mock.get_commit.assert_called_with(sha)
Ejemplo n.º 19
0
 def setUp(self):
     self.coreMock = mopidy.core.Core(None, [])
     self.buttonPressEvent = lib.Event()
     playback = Mock()
     playback.mute = self.WithGet(False)
     playback.volume = self.WithGet(50)
     playback.state = self.WithGet(mopidy.core.PlaybackState.STOPPED)
     self.coreMock.playback = playback
    def test_delete_blackhole_routes(self):
        # prepare
        active_route = Mock()
        active_route.state = 'active'
        blackhole_route = Mock()
        blackhole_route.state = 'blackhole'

        route_table = Mock()
        route_table.routes = [active_route, blackhole_route]

        # act
        self.route_table_service.delete_blackhole_routes(
            route_table=route_table)

        # assert
        self.assertTrue(blackhole_route.delete.called)
        self.assertFalse(active_route.delete.called)
Ejemplo n.º 21
0
    def test_we_can_get_all_instances_with_region(self, mock_landlord, mock_ec2):
        persistence.save('Instance1', 'v43')
        persistence.save('Instance2', 'v43')
        mock_landlord.Tenant = StubLandlord
        mock_connection = Mock()
        mock_ec2.connect_to_region.return_value = mock_connection

        instance1 = Mock()
        instance1.id = 'i-938372'
        instance1.ip_address = '192.1.11.1'
        instance1.state = 'running'
        instance1.launch_time = datetime.date.today().isoformat()
        instance1.tags = {'Name': 'STAGE-Instance-1', 'Project': 'Instance', 'Version': 'v43', 'StopTime' : '8', 'StartTime': '6'}

        instance2 = Mock()
        instance2.id = 'i-542211'
        instance2.state = 'stopped'
        instance2.ip_address = None
        instance2.launch_time = datetime.date.today().isoformat()
        instance2.tags = {'Name': 'STAGE-Instance-2', 'Project': 'Instance', 'Version': 'v43', 'StopTime' : '9', 'StartTime': '7'}

        mock_connection.get_only_instances.return_value = [instance1, instance2]

        instances = ec2.get_all_instances('myRegion')

        mock_ec2.connect_to_region.assert_called_with('myRegion', aws_access_key_id='aws.id',
                                                      aws_secret_access_key='aws.secret')
        mock_connection.get_only_instances.assert_called_with(filters={"tag:Deployer": "igor"})
        self.assertEquals(len(instances), 2)
        self.assertEquals(instances[0]['name'], 'Instance-1')
        self.assertEquals(instances[0]['version'], 'v43')
        self.assertEquals(instances[0]['stopTime'], '8')
        self.assertEquals(instances[0]['startTime'], '6')
        self.assertEquals(instances[0]['project'], 'Instance')
        self.assertEquals(instances[0]['date'], datetime.date.today().isoformat())
        self.assertEquals(instances[0]['ip'], '192.1.11.1')
        self.assertEquals(instances[0]['status'], 'running')
        self.assertEquals(instances[1]['name'], 'Instance-2')
        self.assertEquals(instances[1]['version'], 'v43')
        self.assertEquals(instances[1]['startTime'], '7')
        self.assertEquals(instances[1]['stopTime'], '9')
        self.assertEquals(instances[1]['project'], 'Instance')
        self.assertEquals(instances[1]['date'], datetime.date.today().isoformat())
        self.assertEquals(instances[1]['ip'], 'None')
        self.assertEquals(instances[1]['status'], 'stopped')
Ejemplo n.º 22
0
    def fake_action_runs(self):
        mock_unknown_machine = Mock(autospec=True)
        mock_ok_machine = Mock(autospec=True)

        mock_unknown_machine.state = ActionRun.UNKNOWN
        mock_ok_machine.state = ActionRun.SUCCEEDED
        self.action_runs = [
            SSHActionRun(
                job_run_id="test.unknown",
                name="test.unknown",
                node=Mock(),
                command_config=Mock(),
                machine=mock_unknown_machine,
                end_time=timeutils.current_time(),
            ),
            SSHActionRun(
                job_run_id="test.succeeded",
                name="test.succeeded",
                node=Mock(),
                command_config=Mock(),
                machine=mock_ok_machine,
            ),
            MesosActionRun(
                job_run_id="test.succeeded",
                name="test.succeeded",
                node=Mock(),
                command_config=Mock(),
                machine=mock_ok_machine,
            ),
            MesosActionRun(
                job_run_id="test.unknown-mesos",
                name="test.unknown-mesos",
                node=Mock(),
                command_config=Mock(),
                machine=mock_unknown_machine,
            ),
            MesosActionRun(
                job_run_id="test.unknown-mesos-done",
                name="test.unknown-mesos-done",
                node=Mock(),
                command_config=Mock(),
                machine=mock_unknown_machine,
                end_time=timeutils.current_time(),
            ),
        ]
Ejemplo n.º 23
0
    def test_update(self, GithubMock):

        gh = Mock()
        GithubMock.return_value = gh

        # setup mocked label
        label = Mock()
        label.color = "171717"
        label.name = "Website"

        label1 = Mock()
        label1.color = "171717"
        label1.name = "API"

        gh.get_user().get_repo().get_labels.return_value = [label, label1]

        # set up mocked issue
        issue = Mock()
        issue.created_at = datetime.now()
        issue.state = "open"
        issue_label = Mock()
        issue_label.color = "FF4D4D"
        issue_label.name = "major outage"
        issue.get_labels.return_value = [issue_label, label]
        comment = Mock()
        issue.get_comments.return_value = [comment, ]

        issue1 = Mock()
        issue1.created_at = datetime.now()
        issue1.state = "open"
        issue1.get_labels.return_value = [issue_label, label1]
        issue1.get_comments.return_value = [comment, ]

        gh.get_user().get_repo().get_issues.return_value = [issue, issue1]
        template = Mock()
        template.decoded_content = b"some foo"
        gh.get_user().get_repo().get_file_contents.return_value = template

        runner = CliRunner()
        result = runner.invoke(update, ["--name", "testrepo", "--token", "token"])
        self.assertEqual(result.exit_code, 0)
        GithubMock.assert_called_with("token")

        gh.get_user().get_repo.assert_called_with(name="testrepo")
        gh.get_user().get_repo().get_labels.assert_called_once_with()
Ejemplo n.º 24
0
    def _gen_rest_client(self):
        instance_a = Mock()
        instance_a.id = 'a_id'
        instance_a.node_id = 'a_type'
        instance_a.runtime_properties = {
            'name': 'value',
            '_transaction': '1'
        }
        instance_b = Mock()
        instance_b.id = 'b_id'
        instance_b.node_id = 'b_type'
        instance_b.runtime_properties = {
            'name': 'other',
            '_transaction': '1'
        }
        instance_c = Mock()
        instance_c.id = 'c_id'
        instance_c.node_id = 'c_type'
        instance_c.runtime_properties = {
            'name': 'other',
            '_transaction': '-'
        }
        instance_d = Mock()
        instance_d.id = 'b_id'
        instance_d.node_id = 'c_type'
        instance_d.runtime_properties = {
            'name': 'other',
        }

        client = Mock()
        client.node_instances.list = Mock(return_value=[
            instance_a, instance_b, instance_c, instance_d])
        client.deployments.get = Mock(return_value={
            'groups': {
                'one_scale': {
                    'members': ['one', 'two']
                },
                'any': {
                    'members': ['one', 'two', "three"]
                },
                'alfa_types': {
                    'members': ['a_type', 'b_type']
                }
            }
        })

        # update instances
        target_node = Mock()
        target_node.id = 'target'
        target_node.version = 1
        target_node.state = 'deleted'
        target_node.runtime_properties = {'a': 'b', 'd': 'e'}

        client.node_instances.update = Mock()
        client.node_instances.get = Mock(return_value=target_node)

        return client
Ejemplo n.º 25
0
 def test_failed_join_report(self):
     res = Mock()
     ts = self.app.GroupResult(uuid(), [res])
     res.state = states.FAILURE
     res.backend.is_cached.return_value = True
     self.assertIs(next(ts._failed_join_report()), res)
     res.backend.is_cached.return_value = False
     with self.assertRaises(StopIteration):
         next(ts._failed_join_report())
Ejemplo n.º 26
0
    def test_status_pending_hypervisor_async_result(self):
        # This test's that when we have an async result from the server,
        # we poll for the status on the interval until we get completed result

        # Setup the test data
        config1, d1 = self.create_fake_config('source1', **self.default_config_args)
        config2, d2 = self.create_fake_config('source2', **self.default_config_args)
        virt1 = Mock()
        virt1.CONFIG_TYPE = 'esx'
        virt2 = Mock()
        virt2.CONFIG_TYPE = 'esx'

        guest1 = Guest('GUUID1', virt1.CONFIG_TYPE, Guest.STATE_RUNNING)
        guest2 = Guest('GUUID2', virt2.CONFIG_TYPE, Guest.STATE_RUNNING)
        assoc1 = {'hypervisors': [Hypervisor('hypervisor_id_1', [guest1])]}
        assoc2 = {'hypervisors': [Hypervisor('hypervisor_id_2', [guest2])]}
        report1 = HostGuestAssociationReport(config1, assoc1)
        report2 = HostGuestAssociationReport(config2, assoc2)
        report1.job_id = 'job1'
        report2.job_id = 'job2'

        data_to_send = {'source1': report1,
                        'source2': report2}
        source_keys = ['source1', 'source2']
        batch_report1 = Mock()  # The "report" to check status
        batch_report1.state = AbstractVirtReport.STATE_CREATED
        datastore = {'source1': report1, 'source2': report2}
        manager = Mock()
        items = [AbstractVirtReport.STATE_PROCESSING, AbstractVirtReport.STATE_PROCESSING,
                 AbstractVirtReport.STATE_PROCESSING, AbstractVirtReport.STATE_FINISHED,
                 AbstractVirtReport.STATE_FINISHED]
        manager.check_report_state = Mock(side_effect=self.check_report_state_closure(items))

        logger = Mock()
        config, d = self.create_fake_config('test', **self.default_config_args)
        terminate_event = Mock()
        interval = 10  # Arbitrary for this test
        options = Mock()
        options.print_ = False
        destination_thread = DestinationThread(logger, config,
                                               source_keys=source_keys,
                                               source=datastore,
                                               dest=manager,
                                               interval=interval,
                                               terminate_event=terminate_event,
                                               oneshot=False, options=self.options)
        # In this test we want to see that the wait method is called when we
        # expect and with what parameters we expect
        destination_thread.wait = Mock()
        destination_thread.is_terminated = Mock(return_value=False)
        destination_thread.submitted_report_and_hash_for_source ={'source1':(report1, 'hash1'),'source2':(report2, 'hash2')}
        reports = destination_thread._get_data_common(source_keys)
        self.assertEqual(0, len(reports))
        reports = destination_thread._get_data_common(source_keys)
        self.assertEqual(1, len(reports))
        reports = destination_thread._get_data_common(source_keys)
        self.assertEqual(2, len(reports))
Ejemplo n.º 27
0
 def test_failed_join_report(self):
     res = Mock()
     ts = self.app.GroupResult(uuid(), [res])
     res.state = states.FAILURE
     res.backend.is_cached.return_value = True
     self.assertIs(next(ts._failed_join_report()), res)
     res.backend.is_cached.return_value = False
     with self.assertRaises(StopIteration):
         next(ts._failed_join_report())
    def test_event_publish_unicode_error(self):
        process = Mock()
        process.process_id = "some_process_id"
        process.state = "500-RUNNING"
        notifier = Notifier()
        notifier.event_pub = Mock()

        notifier.event_pub.publish_event.side_effect = Exception()
        notifier.notify_process(process)
    def test_event_publish_unicode_error(self):
        process = Mock()
        process.process_id = "some_process_id"
        process.state = "500-RUNNING"
        notifier = Notifier()
        notifier.event_pub = Mock()

        notifier.event_pub.publish_event.side_effect = Exception()
        notifier.notify_process(process)
Ejemplo n.º 30
0
    def test_send_data_poll_hypervisor_async_result(self):
        # This test's that when we have an async result from the server,
        # we poll for the result

        # Setup the test data
        config1, d1 = self.create_fake_config('source1', **self.default_config_args)
        config2, d2 = self.create_fake_config('source2', **self.default_config_args)
        virt1 = Mock()
        virt1.CONFIG_TYPE = 'esx'
        virt2 = Mock()
        virt2.CONFIG_TYPE = 'esx'

        guest1 = Guest('GUUID1', virt1.CONFIG_TYPE, Guest.STATE_RUNNING)
        guest2 = Guest('GUUID2', virt2.CONFIG_TYPE, Guest.STATE_RUNNING)
        assoc1 = {'hypervisors': [Hypervisor('hypervisor_id_1', [guest1])]}
        assoc2 = {'hypervisors': [Hypervisor('hypervisor_id_2', [guest2])]}
        report1 = HostGuestAssociationReport(config1, assoc1)
        report2 = HostGuestAssociationReport(config2, assoc2)

        data_to_send = {'source1': report1,
                        'source2': report2}
        source_keys = ['source1', 'source2']
        batch_report1 = Mock()  # The "report" to check status
        batch_report1.state = AbstractVirtReport.STATE_CREATED
        datastore = {'source1': report1, 'source2': report2}
        manager = Mock()
        items = [ManagerThrottleError(), ManagerThrottleError(), ManagerThrottleError(), AbstractVirtReport.STATE_FINISHED]
        manager.check_report_state = Mock(side_effect=self.check_report_state_closure(items))

        logger = Mock()
        config, d = self.create_fake_config('test', **self.default_config_args)
        terminate_event = Mock()
        interval = 10  # Arbitrary for this test
        options = Mock()
        options.print_ = False
        destination_thread = DestinationThread(logger, config,
                                               source_keys=source_keys,
                                               source=datastore,
                                               dest=manager,
                                               interval=interval,
                                               terminate_event=terminate_event,
                                               oneshot=False, options=self.options)
        # In this test we want to see that the wait method is called when we
        # expect and with what parameters we expect
        destination_thread.wait = Mock()
        destination_thread.is_terminated = Mock(return_value=False)
        destination_thread.check_report_status(batch_report1)
        # There should be three waits, one after the job is submitted with duration of
        # MinimumJobPollingInterval. The second and third with duration MinimumJobPollInterval * 2
        # (and all subsequent calls as demonstrated by the third wait)
        destination_thread.wait.assert_has_calls([
            call(wait_time=MinimumJobPollInterval),
            call(wait_time=MinimumJobPollInterval * 2),
            call(wait_time=MinimumJobPollInterval * 2)])
Ejemplo n.º 31
0
    def test_waiter_multi(self):
        helper.change_to_stopped(Mock())

        instance.state['Name'] = InstanceWaiter.RUNNING

        inst = Mock()
        inst.state = dict()
        inst.state['Name'] = InstanceWaiter.STOPPED

        res = self.instance_waiter.multi_wait([instance, inst], InstanceWaiter.STOPPED)
        self.assertEqual(res, [instance, inst])
        self.assertTrue(instance.reload.call_count, 2)
Ejemplo n.º 32
0
 def test_get_status_to_pending(self):
     # get status for a task that hasn't begun to run yet
     instructor_task = self._create_entry()
     task_id = instructor_task.task_id
     mock_result = Mock()
     mock_result.task_id = task_id
     mock_result.state = PENDING
     output = self._test_get_status_from_result(task_id, mock_result)
     for key in ['message', 'succeeded', 'task_progress']:
         self.assertNotIn(key, output)
     self.assertEquals(output['task_state'], 'PENDING')
     self.assertTrue(output['in_progress'])
Ejemplo n.º 33
0
 def test_get_status_to_pending(self):
     # get status for a task that hasn't begun to run yet
     instructor_task = self._create_entry()
     task_id = instructor_task.task_id
     mock_result = Mock()
     mock_result.task_id = task_id
     mock_result.state = PENDING
     output = self._test_get_status_from_result(task_id, mock_result)
     for key in ['message', 'succeeded', 'task_progress']:
         self.assertNotIn(key, output)
     self.assertEquals(output['task_state'], 'PENDING')
     self.assertTrue(output['in_progress'])
Ejemplo n.º 34
0
    def test_unreserved_instance_count(self):
        from ZenPacks.zenoss.AWS.utils import unreserved_instance_count

        instance = Mock()
        instance.state = 'running'
        instance.spot_instance_request_id = False

        ec2_conn = Mock()
        ec2_conn.get_only_instances.return_value = [instance] * 10
        ec2_conn.get_all_reserved_instances.return_value = range(5)

        self.assertEquals(unreserved_instance_count(ec2_conn, instance), 5)
Ejemplo n.º 35
0
    def fake_action_runs(self):
        mock_unknown_machine = Mock(autospec=True)
        mock_ok_machine = Mock(autospec=True)

        mock_unknown_machine.state = ActionRun.UNKNOWN
        mock_ok_machine.state = ActionRun.SUCCEEDED
        self.action_runs = [
            SSHActionRun(
                job_run_id="test.unknown",
                name="test.unknown",
                node=Mock(),
                machine=mock_unknown_machine,
                end_time=timeutils.current_time(),
            ),
            SSHActionRun(
                job_run_id="test.succeeded",
                name="test.succeeded",
                node=Mock(),
                machine=mock_ok_machine,
            ),
            MesosActionRun(
                job_run_id="test.succeeded",
                name="test.succeeded",
                node=Mock(),
                machine=mock_ok_machine,
            ),
            MesosActionRun(
                job_run_id="test.unknown-mesos",
                name="test.unknown-mesos",
                node=Mock(),
                machine=mock_unknown_machine,
            ),
            MesosActionRun(
                job_run_id="test.unknown-mesos-done",
                name="test.unknown-mesos-done",
                node=Mock(),
                machine=mock_unknown_machine,
                end_time=timeutils.current_time(),
            ),
        ]
Ejemplo n.º 36
0
  def testGetSuggestedInstancesNoRunning(self, getEC2InstancesMock):
    instanceMock1 = Mock(spec="boto.ec2.instance.Instance")
    instanceMock1.state = "stopped"
    getEC2InstancesMock.return_value = [
        instanceMock1,
    ]

    suggestions = ec2_utils.getSuggestedInstances("dummy-region")
    self.assertIsInstance(suggestions, types.GeneratorType)
    suggestions = list(suggestions)

    self.assertSequenceEqual(suggestions, [])
    getEC2InstancesMock.assert_call_once_with("dummy-region")
Ejemplo n.º 37
0
    def testGetSuggestedInstancesNoRunning(self, getEC2InstancesMock):
        instanceMock1 = Mock(spec="boto.ec2.instance.Instance")
        instanceMock1.state = "stopped"
        getEC2InstancesMock.return_value = [
            instanceMock1,
        ]

        suggestions = ec2_utils.getSuggestedInstances("dummy-region")
        self.assertIsInstance(suggestions, types.GeneratorType)
        suggestions = list(suggestions)

        self.assertSequenceEqual(suggestions, [])
        getEC2InstancesMock.assert_call_once_with("dummy-region")
Ejemplo n.º 38
0
def test_get_ticket_from_issue(ticket):
    issue = Mock(["body", "number", "state", "title"])
    issue.body = "MockBody"
    issue.number = 123
    issue.state = "MockState"
    issue.title = "MockTitle"
    ret = get_ticket_from_issue(issue)
    assert_called_once(
        ticket,
        (),
        {"identifier": 123, "description": "MockBody", "title": "MockTitle", "owner": None, "state": "MockState"},
    )
    assert_equal(ticket.return_value, ret)
Ejemplo n.º 39
0
 def _get_output_for_task_success(self, attempted, updated, total, student=None):
     """returns the task_id and the result returned by instructor_task_status()."""
     # view task entry for task in progress
     instructor_task = self._create_progress_entry(student)
     task_id = instructor_task.task_id
     mock_result = Mock()
     mock_result.task_id = task_id
     mock_result.state = SUCCESS
     mock_result.result = {'attempted': attempted,
                           'updated': updated,
                           'total': total,
                           'action_name': 'rescored'}
     output = self._test_get_status_from_result(task_id, mock_result)
     return output
Ejemplo n.º 40
0
 def test_update_progress_to_revoked(self):
     # view task entry for task in progress that later fails
     instructor_task = self._create_progress_entry()
     task_id = instructor_task.task_id
     mock_result = Mock()
     mock_result.task_id = task_id
     mock_result.state = REVOKED
     output = self._test_get_status_from_result(task_id, mock_result)
     self.assertEquals(output['message'], "Task revoked before running")
     self.assertEquals(output['succeeded'], False)
     self.assertEquals(output['task_state'], REVOKED)
     self.assertFalse(output['in_progress'])
     expected_progress = {'message': "Task revoked before running"}
     self.assertEquals(output['task_progress'], expected_progress)
Ejemplo n.º 41
0
    def test_is_commit_successful(self, sha, statuses, state, expected):
        mock_combined_status = Mock(spec=CommitCombinedStatus)
        mock_combined_status.statuses = statuses
        mock_combined_status.state = state

        commit_mock = Mock(spec=Commit)
        commit_mock.get_combined_status.return_value = mock_combined_status
        self.repo_mock.get_commit.return_value = commit_mock

        response = self.api.is_commit_successful(sha)

        self.assertEqual(response, expected)
        commit_mock.get_combined_status.assert_called()
        self.repo_mock.get_commit.assert_called_with(sha)
Ejemplo n.º 42
0
 def test_update_progress_to_revoked(self):
     # view task entry for task in progress that later fails
     instructor_task = self._create_progress_entry()
     task_id = instructor_task.task_id
     mock_result = Mock()
     mock_result.task_id = task_id
     mock_result.state = REVOKED
     output = self._test_get_status_from_result(task_id, mock_result)
     self.assertEquals(output['message'], "Task revoked before running")
     self.assertEquals(output['succeeded'], False)
     self.assertEquals(output['task_state'], REVOKED)
     self.assertFalse(output['in_progress'])
     expected_progress = {'message': "Task revoked before running"}
     self.assertEquals(output['task_progress'], expected_progress)
Ejemplo n.º 43
0
 def gen_mock_instance(self, ctx, state, instance_id=u"a_id"):
     a_instance = Mock()
     a_instance.id = instance_id
     a_instance.state = state
     a_instance.send_event = mock_send_event
     a_instance.set_state = mock_set_state
     a_instance.node.operations = []
     a_instance.node.type_hierarchy = [u"test_type"]
     a_node = Mock()
     a_node.id = u"a_node_id"
     a_node.instances = [a_instance]
     ctx.nodes.append(a_node)
     ctx.node_instances.append(a_instance)
     return a_instance
Ejemplo n.º 44
0
    def test_dispatch(self):
        view = AccountConfigView()
        request = HttpRequest()
        request.POST = {'account': '1234567-8910'}

        pipeline = Mock()
        pipeline.state = {'accounts': self.accounts}
        pipeline.fetch_state = lambda key: pipeline.state[key]
        pipeline.bind_state = lambda name, value: pipeline.state.update({name: value})

        view.dispatch(request, pipeline)

        assert pipeline.fetch_state(key='instance') == 'sentry2.visualstudio.com'
        assert pipeline.fetch_state(key='account') == self.accounts[1]
        assert pipeline.next_step.call_count == 1
Ejemplo n.º 45
0
    def test_dispatch(self):
        view = ProjectConfigView()
        request = HttpRequest()
        request.POST = {'project': 'first-project-id'}

        pipeline = Mock()
        pipeline.state = {'projects': self.projects}
        pipeline.fetch_state = lambda key: pipeline.state[key]
        pipeline.bind_state = lambda name, value: pipeline.state.update(
            {name: value})

        view.dispatch(request, pipeline)

        assert pipeline.fetch_state(key='project') == self.projects[0]
        assert pipeline.next_step.call_count == 1
Ejemplo n.º 46
0
    def test_dispatch(self):
        view = AccountConfigView()
        request = HttpRequest()
        request.POST = {'account': '1234567-8910'}

        pipeline = Mock()
        pipeline.state = {'accounts': self.accounts}
        pipeline.fetch_state = lambda key: pipeline.state[key]
        pipeline.bind_state = lambda name, value: pipeline.state.update({name: value})

        view.dispatch(request, pipeline)

        assert pipeline.fetch_state(key='instance') == 'sentry2.visualstudio.com'
        assert pipeline.fetch_state(key='account') == self.accounts[1]
        assert pipeline.next_step.call_count == 1
Ejemplo n.º 47
0
    def _given_instance_mock(self):
        instance_mock = Mock(boto.ec2.instance, image_id="ami-1112")
        instance_mock.id = INSTANCE_ID
        instance_mock.instance_type = "m1.small"
        instance_mock.launch_time = "01.01.2015"
        instance_mock.public_dns_name = "test.aws.com"
        instance_mock.key_name = "test-ssh-key"
        instance_mock.region = self.positive_fake_region
        instance_mock._state = boto.ec2.instance.InstanceState(16, "running")
        instance_mock.state = instance_mock._state.name

        self.ec2_mock.connect_to_region.return_value.get_only_instances.return_value = [
            instance_mock
        ]
        return instance_mock
Ejemplo n.º 48
0
def test_get_ticket_from_issue(ticket):
    issue = Mock(['body', 'number', 'state', 'title'])
    issue.body = 'MockBody'
    issue.number = 123
    issue.state = 'MockState'
    issue.title = 'MockTitle'
    ret = get_ticket_from_issue(issue)
    assert_called_once(
        ticket, (), {
            'identifier': 123,
            'description': 'MockBody',
            'title': 'MockTitle',
            'owner': None,
            'state': 'MockState',
        })
    assert_equal(ticket.return_value, ret)
Ejemplo n.º 49
0
    def test_filter_validation(self, exclude_contexts, include_contexts,
                               expected_contexts):
        filterable_states = ['passed', 'pending', None, 'failed']

        with patch.object(Github,
                          'get_organization',
                          return_value=Mock(name='org-mock',
                                            spec=Organization)):
            with patch.object(Github,
                              'get_repo',
                              return_value=Mock(name='repo-mock',
                                                spec=Repository)) as repo_mock:
                api = GitHubAPI('test-org',
                                'test-repo',
                                token='abc123',
                                exclude_contexts=exclude_contexts,
                                include_contexts=include_contexts)
        api.log_rate_limit = Mock(return_value=None)

        mock_combined_status = Mock(name='combined-status',
                                    spec=CommitCombinedStatus)
        mock_combined_status.statuses = [
            Mock(name='{}-status'.format(state),
                 spec=CommitStatus,
                 context='{}-status'.format(state),
                 state=state) for state in filterable_states
        ]
        mock_combined_status.state = None
        mock_combined_status.url = None

        commit_mock = Mock(name='commit', spec=Commit, url="some.fake.repo/")
        commit_mock.get_combined_status.return_value = mock_combined_status
        repo_mock.return_value.get_commit.return_value = commit_mock
        commit_mock._requester = Mock(name='_requester')  # pylint: disable=protected-access
        # pylint: disable=protected-access
        commit_mock._requester.requestJsonAndCheck.return_value = ({}, {
            'check_suites': [{
                'app': {
                    'name': '{}-check'.format(state)
                },
                'conclusion': state,
                'url': 'some.fake.repo'
            } for state in filterable_states]
        })
        filtered_results = api.filter_validation_results(
            api.get_validation_results('deadbeef'))
        assert set(expected_contexts) == set(filtered_results.keys())
Ejemplo n.º 50
0
    def test_znode_watch_triggered_for_child_events_causes_reprocess(self):
        mock_zk = _mock_zk()

        # we're asserting on the side effects of creating the group
        ActiveKazooGroup(mock_zk, DEFAULT_PATH)

        assert mock_zk.get_children_async.call_count == 1

        _, watch_callback = mock_zk.get_children_async.call_args[0]

        mock_watch_event = Mock()
        mock_watch_event.state = KeeperState.CONNECTED
        mock_watch_event.type = EventType.CHILD

        watch_callback(mock_watch_event)

        assert mock_zk.get_children_async.call_count == 2
Ejemplo n.º 51
0
    def test_znode_watch_triggered_for_deleted_znode_causes_wait_for_it_to_exist(self):
        mock_zk = _mock_zk()

        # we're asserting on the side effects of creating the group
        ActiveKazooGroup(mock_zk, DEFAULT_PATH)

        assert mock_zk.exists_async.call_count == 0

        _, watch_callback = mock_zk.get_children_async.call_args[0]

        mock_watch_event = Mock()
        mock_watch_event.state = KeeperState.CONNECTED
        mock_watch_event.type = EventType.DELETED

        watch_callback(mock_watch_event)

        assert mock_zk.exists_async.call_count == 1
Ejemplo n.º 52
0
 def test_update_progress_to_progress(self):
     # view task entry for task in progress
     instructor_task = self._create_progress_entry()
     task_id = instructor_task.task_id
     mock_result = Mock()
     mock_result.task_id = task_id
     mock_result.state = PROGRESS
     mock_result.result = {'attempted': 5,
                           'updated': 4,
                           'total': 10,
                           'action_name': 'rescored'}
     output = self._test_get_status_from_result(task_id, mock_result)
     self.assertEquals(output['message'], "Progress: rescored 4 of 5 so far (out of 10)")
     self.assertEquals(output['succeeded'], False)
     self.assertEquals(output['task_state'], PROGRESS)
     self.assertTrue(output['in_progress'])
     self.assertEquals(output['task_progress'], mock_result.result)
Ejemplo n.º 53
0
 def fake_job(self):
     job = Mock(Job)
     job.id = 'foo'
     job.description = ""
     job.ms_filename = ""
     job.dir = '/somedir/foo'
     job.state = 'STOPPED'
     job.db = Mock(JobDb)
     job.db.runInfo.return_value = 'bla'
     job.db.maxMSLevel.return_value = 3
     job.db.molecules.return_value = {'total': 3, 'rows': [1, 2, 3]}
     job.db.moleculesTotalCount.return_value = 3
     job.db.scansWithMolecules.return_value = [4, 5]
     job.db.chromatogram.return_value = [1, 2, 3]
     job.db.extractedIonChromatogram.return_value = [1, 2, 3]
     job.db.fragments.return_value = [1, 2, 3]
     return job