Example #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)])
Example #2
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)])
Example #3
0
    def test_collection(self):
        """Same as src; looking for collection{,_id,_uuid} in request."""
        b = self.get_button()
        eq_(b.collection, None)

        self.request.GET["collection_uuid"] = "aa"
        b = self.get_button()
        eq_(b.collection, "aa")

        self.request.GET["collection_id"] = "bb"
        b = self.get_button()
        eq_(b.collection, "bb")

        self.request.GET["collection"] = "cc"
        b = self.get_button()
        eq_(b.collection, "cc")

        self.context["collection"] = "dd"
        b = self.get_button()
        eq_(b.collection, "dd")

        b = self.get_button(collection="ee")
        eq_(b.collection, "ee")

        c = Mock()
        c.uuid = "ff"
        b = self.get_button(collection=c)
        eq_(b.collection, "ff")
Example #4
0
    def test_collection(self):
        """Same as src; looking for collection{,_id,_uuid} in request."""
        b = self.get_button()
        assert b.collection is None

        self.request.GET["collection_uuid"] = "aa"
        b = self.get_button()
        assert b.collection == "aa"

        self.request.GET["collection_id"] = "bb"
        b = self.get_button()
        assert b.collection == "bb"

        self.request.GET["collection"] = "cc"
        b = self.get_button()
        assert b.collection == "cc"

        self.context["collection"] = "dd"
        b = self.get_button()
        assert b.collection == "dd"

        b = self.get_button(collection="ee")
        assert b.collection == "ee"

        c = Mock()
        c.uuid = "ff"
        b = self.get_button(collection=c)
        assert b.collection == "ff"
Example #5
0
    def test_unbind(self, mock_gofer_agent):
        context = Mock()
        context.uuid = "123"
        context.url = "http://broker.com"
        context.secret = "123-secret"
        context.details = {"task_id": "4567"}
        context.get_timeout = Mock(return_value=90)
        context.reply_queue = "pulp.task"
        context.watchdog = "pulp-watchdog"

        mock_agent = Mock()
        mock_gofer_agent.return_value = mock_agent
        mock_consumer = Mock()
        mock_agent.Consumer = Mock(return_value=mock_consumer)

        bindings = []
        options = {}

        Consumer.unbind(context, bindings, options)

        mock_gofer_agent.assert_called_with(
            context.uuid,
            ctag=context.reply_queue,
            url=context.url,
            secret=context.secret,
            timeout=context.get_timeout(),
            watchdog=context.watchdog,
            any=context.details,
        )

        mock_consumer.unbind.assert_called_with(bindings, options)
    def test_update_button_disabled(self):
        # Need an unregistered consumer object:
        unregistered_consumer = Mock()
        unregistered_consumer.uuid = None
        unregistered_consumer.name = None

        dialog = factsgui.SystemFactsDialog(self.uep, unregistered_consumer, self.stub_facts)
        dialog.show()

        enabled = dialog.update_button.get_property("sensitive")

        self.assertFalse(enabled)
Example #7
0
    def test_fix_link(self):
        b = self.get_button()
        eq_(b.fix_link("foo.com"), "foo.com")

        b = self.get_button(src="src")
        eq_(b.fix_link("foo.com"), "foo.com?src=src")

        collection = Mock()
        collection.uuid = "xxx"
        b = self.get_button(collection=collection)
        eq_(b.fix_link("foo.com"), "foo.com?collection_id=xxx")

        b = self.get_button(collection=collection, src="src")
        eq_(b.fix_link("foo.com"), "foo.com?src=src&collection_id=xxx")
Example #8
0
    def test_fix_link(self):
        b = self.get_button()
        assert b.fix_link("foo.com") == "foo.com"

        b = self.get_button(src="src")
        assert b.fix_link("foo.com") == "foo.com?src=src"

        collection = Mock()
        collection.uuid = "xxx"
        b = self.get_button(collection=collection)
        assert b.fix_link("foo.com") == "foo.com?collection_id=xxx"

        b = self.get_button(collection=collection, src="src")
        self.assertUrlEqual(b.fix_link("foo.com"), "foo.com?src=src&collection_id=xxx")
Example #9
0
    def test_send(self, mock_gofer_agent):
        context = Mock()
        context.uuid = "123"
        context.url = "http://broker.com"
        context.secret = "123-secret"

        mock_agent = Mock()
        mock_gofer_agent.return_value = mock_agent
        mock_profile = Mock()
        mock_agent.Profile = Mock(return_value=mock_profile)

        Profile.send(context)

        mock_gofer_agent.assert_called_with(context.uuid, url=context.url, secret=context.secret)
        mock_profile.send.assert_called_with()
Example #10
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)
Example #11
0
    def test_send(self, mock_gofer_agent):
        context = Mock()
        context.uuid = "123"
        context.url = "http://broker.com"
        context.secret = "123-secret"

        task_id = "5678"
        criteria = {"match": {"task_id": task_id}}

        mock_agent = Mock()
        mock_gofer_agent.return_value = mock_agent
        mock_admin = Mock()
        mock_agent.Admin = Mock(return_value=mock_admin)

        agent = PulpAgent()
        agent.cancel(context, task_id)

        mock_gofer_agent.assert_called_with(context.uuid, url=context.url, secret=context.secret, async=True)
        mock_admin.cancel.assert_called_with(criteria=criteria)
Example #12
0
    def test_unregistered(self, mock_gofer_agent):
        context = Mock()
        context.uuid = "123"
        context.url = "http://broker.com"
        context.secret = "123-secret"

        mock_agent = Mock()
        mock_gofer_agent.return_value = mock_agent
        mock_consumer = Mock()
        mock_agent.Consumer = Mock(return_value=mock_consumer)

        # test capability

        Consumer.unregistered(context)

        # validation

        mock_gofer_agent.assert_called_with(context.uuid, url=context.url, secret=context.secret, async=True)

        mock_consumer.unregistered.assert_called_with()
 def setUp(self):
     self.resource = Mock()
     self.context = Mock()
     session = Mock()
     remote_resource = Mock()
     remote_resource.fullname = "this is full name of the remote resource"
     remote_resource.uuid = "this is full uuis of the remote resource"
     self.connection_details = TestCredentials()
     self.context.resource = self.resource
     self.context.remote_endpoints = [self.resource]
     self.command_orchestrator = CommandOrchestrator(self.context)
     self.command_orchestrator.cs_helper = Mock()
     self.command_orchestrator.cs_helper.get_session = Mock(return_value=session)
     self.command_orchestrator.cs_helper.get_connection_details = Mock(return_value=self.connection_details)
     self.command_orchestrator.vc_data_model.default_dvswitch = "QualiSB\\dvSwitch"
     self.command_orchestrator.vc_data_model.holding_network = "QualiSB/anetwork"
     self.ports = Mock()
     self.command_orchestrator._parse_remote_model = Mock(return_value=remote_resource)
     self.command_orchestrator.connection_orchestrator.disconnector.default_network = (
         self.command_orchestrator.vc_data_model.holding_network
     )
Example #14
0
    def test_cancel(self, agent, context, mock_factory):
        consumer = {"id": "xyz"}
        mock_consumer_manager = Mock()
        mock_consumer_manager.get_consumer = Mock(return_value=consumer)
        mock_factory.consumer_manager = Mock(return_value=mock_consumer_manager)

        mock_context = Mock()
        mock_context.uuid = "test-uuid"
        mock_context.url = "http://broker.com"
        context.return_value = mock_context

        mock_agent = Mock()
        agent.return_value = mock_agent

        # test manager

        task_id = "1234"
        agent_manager = AgentManager()
        consumer_id = "abc"
        agent_manager.cancel_request(consumer_id, task_id)

        # validations

        mock_agent.cancel.assert_called_with(mock_context, task_id)
 def setUp(self):
     self.resource = create_autospec(ResourceInfo)
     self.resource.ResourceModelName = "VMwarev Center"
     self.resource.ResourceAttributes = {
         "User": "user",
         "Password": "123",
         "Default dvSwitch": "switch1",
         "Holding Network": "anetwork",
         "Default Port Group Location": "Quali",
         "VM Cluster": "Quali",
         "VM Location": "Quali",
         "VM Resource Pool": "Quali",
         "VM Storage": "Quali",
         "Shutdown Method": "hard",
         "OVF Tool Path": "C\\program files\ovf",
         "Execution Server Selector": "",
         "Reserved Networks": "vlan65",
         "Default Datacenter": "QualiSB",
     }
     self.context = Mock()
     session = Mock()
     remote_resource = Mock()
     remote_resource.fullname = "this is full name of the remote resource"
     remote_resource.uuid = "this is full uuis of the remote resource"
     self.connection_details = Mock()
     self.context.resource = self.resource
     self.context.resource.app_context = Mock()
     self.context.remote_endpoints = Mock()
     self.context.remote_endpoints = [self.resource]
     self.command_orchestrator = CommandOrchestrator()
     self.command_orchestrator.command_wrapper.execute_command_with_connection = Mock(return_value=True)
     self.command_orchestrator.cs_helper = Mock()
     self.command_orchestrator.cs_helper.get_session = Mock(return_value=session)
     self.command_orchestrator.cs_helper.get_connection_details = Mock(return_value=self.connection_details)
     self.ports = [Mock()]
     self.command_orchestrator._parse_remote_model = Mock(return_value=remote_resource)