def test_init_no_unique_id_with_both_remote_and_command_services(self):
        with self.create_client(max_retries=0) as dxl_client:
            dxl_client.connect()

            with MockEpoServer(dxl_client, id_number=0,
                               use_commands_service=True), \
                    MockEpoServer(dxl_client, id_number=1,
                                  use_commands_service=False):
                self.assertRaisesRegex(
                    Exception, "Multiple ePO DXL services are registered.*" +
                    LOCAL_TEST_SERVER_NAME + '0' + ", " +
                    LOCAL_TEST_SERVER_NAME + '1', EpoClient, dxl_client)
    def test_init_same_unique_id_remote_preferred_to_commands_service(self):
        with self.create_client(max_retries=0) as dxl_client:
            dxl_client.connect()

            with MockEpoServer(dxl_client, use_commands_service=True,
                               user_authorized=False), \
                     MockEpoServer(dxl_client,
                                   use_commands_service=False):
                epo_client = EpoClient(dxl_client)
                self.assertEqual(
                    epo_client._epo_unique_id,
                    LOCAL_TEST_SERVER_NAME + str(DEFAULT_EPO_SERVER_ID))
                self.assertIn("core.help", epo_client.help())
    def test_init_valid_remote_unique_id_and_unauthorized_command_service(
            self):
        with self.create_client(max_retries=0) as dxl_client:
            dxl_client.connect()

            with MockEpoServer(dxl_client,
                               use_commands_service=True,
                               id_number="0",
                               user_authorized=False),\
                    MockEpoServer(dxl_client,
                                  use_commands_service=False,
                                  id_number=1):
                epo_id = LOCAL_TEST_SERVER_NAME + "1"
                epo_client = EpoClient(dxl_client, epo_unique_id=epo_id)
                self.assertEqual(epo_client._epo_unique_id, epo_id)
                self.assertIn("core.help", epo_client.help())
    def test_system_find_example(self):
        # Modify sample file to include necessary sample data
        sample_filename = self.BASIC_FOLDER + "/basic_system_find_example.py"
        temp_sample_file = TempSampleFile(sample_filename)

        target_line = "EPO_UNIQUE_ID = "
        replacement_line = target_line + "\"" \
                           + LOCAL_TEST_SERVER_NAME \
                           + str(DEFAULT_EPO_SERVER_ID) \
                           + "\"\n"
        temp_sample_file.write_file_line(target_line, replacement_line)

        target_line = "SEARCH_TEXT = "
        replacement_line = target_line + "\"" + SYSTEM_FIND_OSTYPE_LINUX + "\"\n"
        temp_sample_file.write_file_line(target_line, replacement_line)

        with self.create_client(max_retries=0) as dxl_client:
            dxl_client.connect()

            with MockEpoServer(dxl_client, id_number=DEFAULT_EPO_SERVER_ID):
                mock_print = self.run_sample(temp_sample_file.temp_file.name)

                mock_print.assert_any_call(
                    StringMatchesRegEx(
                        self.expected_print_output(SYSTEM_FIND_PAYLOAD)))

                mock_print.assert_any_call(StringDoesNotContain("Error"))

            dxl_client.disconnect()
Пример #5
0
    def test_lookupidentifiers(self):
        with BaseClientTest.create_client(max_retries=0) as dxl_client:
            dxl_client.connect()

            with MockEpoServer(dxl_client):
                epo_ids = EpoClient.lookup_epo_unique_identifiers(dxl_client)

                # Load find result into dictionary
                for epo_id in epo_ids:
                    self.assertIn(LOCAL_TEST_SERVER_NAME, epo_id)

            dxl_client.disconnect()
    def test_init_valid_unique_id(self):
        with self.create_client(max_retries=0) as dxl_client:
            dxl_client.connect()

            for use_commands_service in [True, False]:
                with MockEpoServer(dxl_client,
                                   use_commands_service=use_commands_service):
                    epo_id = LOCAL_TEST_SERVER_NAME +\
                             str(DEFAULT_EPO_SERVER_ID)
                    epo_client = EpoClient(dxl_client, epo_unique_id=epo_id)
                    self.assertEqual(epo_client._epo_unique_id, epo_id)
                    self.assertIn("core.help", epo_client.help())
    def test_lookup_epo_unique_identifiers(self):
        with self.create_client(max_retries=0) as dxl_client:
            dxl_client.connect()

            for use_commands_service in [True, False]:
                with MockEpoServer(dxl_client,
                                   use_commands_service=use_commands_service):
                    epo_ids = EpoClient.lookup_epo_unique_identifiers(
                        dxl_client)
                    self.assertEqual(
                        {LOCAL_TEST_SERVER_NAME + str(DEFAULT_EPO_SERVER_ID)},
                        epo_ids)
Пример #8
0
    def test_helpcommand(self):
        with BaseClientTest.create_client(max_retries=0) as dxl_client:
            # Set up client, and register mock service
            epo_client = EpoClient(dxl_client,
                                   epo_unique_id=LOCAL_TEST_SERVER_NAME +
                                   str(DEFAULT_EPO_SERVER_ID))
            dxl_client.connect()

            with MockEpoServer(dxl_client):
                result = epo_client.help()

                self.assertIn(result, HELP_CMD_RESPONSE_PAYLOAD)

            dxl_client.disconnect()
    def test_init_invalid_unique_id(self):
        with self.create_client(max_retries=0) as dxl_client:
            dxl_client.connect()

            for use_commands_service in [True, False]:
                with MockEpoServer(dxl_client,
                                   use_commands_service=use_commands_service):
                    epo_id = LOCAL_TEST_SERVER_NAME + "1"
                    self.assertRaisesRegex(
                        Exception,
                        "No ePO DXL services are registered " +
                        "with the DXL fabric for id: " + epo_id,
                        EpoClient,
                        dxl_client,
                        epo_unique_id=epo_id)
    def test_help(self):
        with self.create_client(max_retries=0) as dxl_client:
            dxl_client.connect()

            for use_commands_service in [True, False]:
                with MockEpoServer(dxl_client,
                                   use_commands_service=use_commands_service):
                    epo_client = EpoClient(
                        dxl_client,
                        epo_unique_id=LOCAL_TEST_SERVER_NAME +
                        str(DEFAULT_EPO_SERVER_ID))

                    # Run it twice to validate the command vs. remote
                    # service failover logic for request topics
                    for _ in range(2):
                        result = epo_client.help()

                        self.assertEqual(result, HELP_CMD_RESPONSE_PAYLOAD)
Пример #11
0
    def test_runcommand(self):
        with BaseClientTest.create_client(max_retries=0) as dxl_client:
            # Set up client, and register mock service
            epo_client = EpoClient(dxl_client,
                                   epo_unique_id=LOCAL_TEST_SERVER_NAME +
                                   str(DEFAULT_EPO_SERVER_ID))
            dxl_client.connect()

            with MockEpoServer(dxl_client):
                res = epo_client.run_command(
                    "system.find", {"searchText": SYSTEM_FIND_CMD_NAME},
                    output_format=OutputFormat.JSON)

                # Load find result into dictionary
                res_list = MessageUtils.json_to_dict(res)

                self.assertEqual(res_list, SYSTEM_FIND_PAYLOAD)

            dxl_client.disconnect()
    def test_run_command(self):
        with self.create_client(max_retries=0) as dxl_client:
            dxl_client.connect()

            for use_commands_service in [True, False]:
                with MockEpoServer(dxl_client,
                                   use_commands_service=use_commands_service):
                    epo_client = EpoClient(
                        dxl_client,
                        epo_unique_id=LOCAL_TEST_SERVER_NAME +
                        str(DEFAULT_EPO_SERVER_ID))

                    # Run it twice to validate the command vs. remote
                    # service failover logic for request topics
                    for _ in range(2):
                        res = epo_client.run_command(
                            "system.find",
                            {"searchText": SYSTEM_FIND_OSTYPE_LINUX},
                            output_format=OutputFormat.JSON)

                        res_list = MessageUtils.json_to_dict(res)

                        self.assertEqual(res_list, SYSTEM_FIND_PAYLOAD)
    def test_core_help_example(self):
        # Modify sample file to include necessary sample data
        sample_filename = self.BASIC_FOLDER + "/basic_core_help_example.py"
        temp_sample_file = TempSampleFile(sample_filename)

        target_line = "EPO_UNIQUE_ID = "
        replacement_line = target_line + "\"" \
                           + LOCAL_TEST_SERVER_NAME \
                           + str(DEFAULT_EPO_SERVER_ID) \
                           + "\"\n"
        temp_sample_file.write_file_line(target_line, replacement_line)

        with self.create_client(max_retries=0) as dxl_client:
            dxl_client.connect()

            with MockEpoServer(dxl_client, id_number=DEFAULT_EPO_SERVER_ID):
                mock_print = self.run_sample(temp_sample_file.temp_file.name)

                mock_print.assert_any_call(
                    StringContains(HELP_CMD_RESPONSE_PAYLOAD))

                mock_print.assert_any_call(StringDoesNotContain("Error"))

            dxl_client.disconnect()