コード例 #1
0
    def test_duplicate_endpoints(self):
        request_headers_mock = MagicMock(return_value=self.mock_headers)
        http_method = self.respond_with_file_contents('data/bundle_with_acls/duplicate_endpoints_tcp.json')
        stdout = MagicMock()

        input_args = MagicMock(**self.default_args)
        with patch('requests.get', http_method), \
                patch('conductr_cli.conduct_url.request_headers', request_headers_mock):
            logging_setup.configure_logging(input_args, stdout)
            result = conduct_acls.acls(input_args)
            self.assertTrue(result)

        request_headers_mock.assert_called_with(input_args)
        http_method.assert_called_with(self.default_url, timeout=DEFAULT_HTTP_TIMEOUT, headers=self.mock_headers)
        self.maxDiff = None
        self.assertEqual(
            as_warn(strip_margin(
                    """|TCP/PORT  SYSTEM      SYSTEM VERSION  ENDPOINT NAME  BUNDLE ID  BUNDLE NAME   STATUS
                       |12001     dup-system  1               duplicate      f804d64    dup-bundle-1  Running
                       |12002     dup-system  1               duplicate      a904d64    dup-bundle-2  Running
                       |
                       |Warning: Multiple endpoints found: dup-system/1/duplicate
                       |Warning: Unable to expose these endpoint via ConductR HAProxy.
                       |Warning: Please ensure the ENDPOINT NAME is unique within a particular SYSTEM and SYSTEM VERSION.
                       |""")),
            self.output(stdout))
コード例 #2
0
    def test_two_bundles_mult_components_endpoints(self):
        http_method = self.respond_with_file_contents('data/two_bundles.json')
        stdout = MagicMock()

        with patch('requests.get', http_method):
            logging_setup.configure_logging(MagicMock(**self.default_args), stdout)
            result = conduct_services.services(MagicMock(**self.default_args))
            self.assertTrue(result)

        http_method.assert_called_with(self.default_url, timeout=DEFAULT_HTTP_TIMEOUT)
        self.assertEqual(
            as_warn(strip_margin("""|SERVICE                   BUNDLE ID  BUNDLE NAME                   STATUS
                                    |http://:6011/comp2-endp2  6e4560e    multi2-comp-multi-endp-1.0.0  Running
                                    |http://:7010/comp3-endp1  6e4560e    multi2-comp-multi-endp-1.0.0  Running
                                    |http://:7011/comp3-endp2  6e4560e    multi2-comp-multi-endp-1.0.0  Running
                                    |http://:8010/comp1-endp1  f804d64    multi-comp-multi-endp-1.0.0   Running
                                    |http://:8011/comp1-endp2  f804d64    multi-comp-multi-endp-1.0.0   Running
                                    |http://:9010/comp2-endp1  f804d64    multi-comp-multi-endp-1.0.0   Running
                                    |http://:9010/comp2-endp1  6e4560e    multi2-comp-multi-endp-1.0.0  Running
                                    |http://:9011/comp2-endp2  f804d64    multi-comp-multi-endp-1.0.0   Running
                                    |
                                    |Warning: Multiple endpoints found for the following services: /comp2-endp2
                                    |Warning: Service resolution for these services is undefined.
                                    |""")),
            self.output(stdout))
コード例 #3
0
    def test_quiet_settings(self):
        stdout = MagicMock()
        stderr = MagicMock()
        logging_setup.configure_logging(MagicMock(**{'quiet': True}), stdout, stderr)

        log = logging.getLogger('conductr_cli')
        log.debug('this is debug')
        log.verbose('this is verbose')
        log.info('this is info')
        log.progress('this is progress', flush=True)
        log.quiet('this is quiet')
        log.warning('this is warning')
        log.error('this is error')
        log.screen('this is screen')

        self.assertFalse(log.is_debug_enabled())
        self.assertFalse(log.is_verbose_enabled())
        self.assertFalse(log.is_info_enabled())
        self.assertFalse(log.is_progress_enabled())
        self.assertTrue(log.is_quiet_enabled())
        self.assertTrue(log.is_warn_enabled())

        self.assertEqual(as_warn(strip_margin("""|this is quiet
                                                 |Warning: this is warning
                                                 |this is screen
                                                 |""")), self.output(stdout))
        self.assertEqual(as_error('Error: this is error\n'), self.output(stderr))
コード例 #4
0
    def test_default_settings(self):
        stdout = MagicMock()
        is_tty_mock = MagicMock(return_value=True)
        stderr = MagicMock()
        logging_setup.configure_logging(MagicMock(), stdout, stderr)

        with patch('sys.stdout.isatty', is_tty_mock):
            log = logging.getLogger('conductr_cli')
            log.debug('this is debug')
            log.verbose('this is verbose')
            log.info('this is info')
            log.progress('this is progress', flush=True)
            log.quiet('this is quiet')
            log.warning('this is warning')
            log.error('this is error')
            log.screen('this is screen')

        self.assertFalse(log.is_debug_enabled())
        self.assertFalse(log.is_verbose_enabled())
        self.assertTrue(log.is_info_enabled())
        self.assertTrue(log.is_progress_enabled())
        self.assertTrue(log.is_quiet_enabled())
        self.assertTrue(log.is_warn_enabled())

        self.assertEqual(
            as_warn(
                strip_margin("""|this is info
                                                 |this is progress
                                                 |this is quiet
                                                 |Warning: this is warning
                                                 |this is screen
                                                 |""")), self.output(stdout))
        self.assertEqual(as_error('Error: this is error\n'),
                         self.output(stderr))
コード例 #5
0
    def test_duplicate_endpoints(self):
        request_headers_mock = MagicMock(return_value=self.mock_headers)
        http_method = self.respond_with_file_contents(
            'data/bundle_with_acls/duplicate_endpoints_tcp.json')
        stdout = MagicMock()

        input_args = MagicMock(**self.default_args)
        with patch('requests.get', http_method), \
                patch('conductr_cli.conduct_url.request_headers', request_headers_mock):
            logging_setup.configure_logging(input_args, stdout)
            result = conduct_acls.acls(input_args)
            self.assertTrue(result)

        request_headers_mock.assert_called_with(input_args)
        http_method.assert_called_with(self.default_url,
                                       timeout=DEFAULT_HTTP_TIMEOUT,
                                       headers=self.mock_headers)
        self.maxDiff = None
        self.assertEqual(
            as_warn(
                strip_margin(
                    """|TCP/PORT  SYSTEM      SYSTEM VERSION  ENDPOINT NAME  BUNDLE ID  BUNDLE NAME   STATUS
                       |12001     dup-system  1               duplicate      f804d64    dup-bundle-1  Running
                       |12002     dup-system  1               duplicate      a904d64    dup-bundle-2  Running
                       |
                       |Warning: Multiple endpoints found: dup-system/1/duplicate
                       |Warning: Unable to expose these endpoint via ConductR HAProxy.
                       |Warning: Please ensure the ENDPOINT NAME is unique within a particular SYSTEM and SYSTEM VERSION.
                       |""")), self.output(stdout))
コード例 #6
0
    def test_two_bundles_mult_components_endpoints(self):
        request_headers_mock = MagicMock(return_value=self.mock_headers)
        http_method = self.respond_with_file_contents(
            'data/bundle_with_services/two_bundles.json')
        stdout = MagicMock()

        input_args = MagicMock(**self.default_args)
        with patch('requests.get', http_method), \
                patch('conductr_cli.conduct_url.request_headers', request_headers_mock):
            logging_setup.configure_logging(input_args, stdout)
            result = conduct_services.services(input_args)
            self.assertTrue(result)

        request_headers_mock.assert_called_with(input_args)
        http_method.assert_called_with(self.default_url,
                                       timeout=DEFAULT_HTTP_TIMEOUT,
                                       headers=self.mock_headers)
        self.assertEqual(
            as_warn(
                strip_margin(
                    """|SERVICE                   BUNDLE ID  BUNDLE NAME                   STATUS
                                    |http://:6011/comp2-endp2  6e4560e    multi2-comp-multi-endp-1.0.0  Running
                                    |http://:7010/comp3-endp1  6e4560e    multi2-comp-multi-endp-1.0.0  Running
                                    |http://:7011/comp3-endp2  6e4560e    multi2-comp-multi-endp-1.0.0  Running
                                    |http://:8010/comp1-endp1  f804d64    multi-comp-multi-endp-1.0.0   Running
                                    |http://:8011/comp1-endp2  f804d64    multi-comp-multi-endp-1.0.0   Running
                                    |http://:9010/comp2-endp1  f804d64    multi-comp-multi-endp-1.0.0   Running
                                    |http://:9010/comp2-endp1  6e4560e    multi2-comp-multi-endp-1.0.0  Running
                                    |http://:9011/comp2-endp2  f804d64    multi-comp-multi-endp-1.0.0   Running
                                    |
                                    |Warning: Multiple endpoints found for the following services: /comp2-endp2
                                    |Warning: Service resolution for these services is undefined.
                                    |""")), self.output(stdout))
コード例 #7
0
    def test_two_bundles_mult_components_endpoints(self):
        self.maxDiff = None
        http_method = self.respond_with_file_contents(
            'data/bundle_with_services/two_bundles.json')
        stdout = MagicMock()

        input_args = MagicMock(**self.default_args)
        with patch('requests.get', http_method):
            logging_setup.configure_logging(input_args, stdout)
            result = conduct_service_names.service_names(input_args)
            self.assertTrue(result)

        http_method.assert_called_with(self.default_url,
                                       timeout=DEFAULT_HTTP_TIMEOUT,
                                       headers={'Host': '127.0.0.1'})
        self.assertEqual(
            as_warn(
                strip_margin(
                    """|SERVICE NAME  BUNDLE ID  BUNDLE NAME                   STATUS
                                    |comp1-endp1   f804d64    multi-comp-multi-endp-1.0.0   Running
                                    |comp1-endp2   f804d64    multi-comp-multi-endp-1.0.0   Running
                                    |comp2-endp1   f804d64    multi-comp-multi-endp-1.0.0   Running
                                    |comp2-endp1   6e4560e    multi2-comp-multi-endp-1.0.0  Running
                                    |comp2-endp2   f804d64    multi-comp-multi-endp-1.0.0   Running
                                    |comp2-endp2   6e4560e    multi2-comp-multi-endp-1.0.0  Running
                                    |comp3-endp1   6e4560e    multi2-comp-multi-endp-1.0.0  Running
                                    |comp3-endp2   6e4560e    multi2-comp-multi-endp-1.0.0  Running
                                    |
                                    |Warning: Multiple endpoints found for the following services: /comp2-endp2
                                    |Warning: Service resolution for these services is undefined.
                                    |""")), self.output(stdout))
コード例 #8
0
    def test_docker_insufficient_cpu(self):
        stdout_mock = MagicMock()
        docker_info_mock = MagicMock(return_value=b'\nTotal Memory: 3.8 GiB\nCPUs: 3')

        logging_setup.configure_logging(MagicMock(), output=stdout_mock)

        with patch('conductr_cli.terminal.docker_info', docker_info_mock):
            sandbox_main.validate_docker_vm(DockerVmType.DOCKER_ENGINE)

        docker_info_mock.assert_called_with()
        self.assertEqual(
            as_warn('Warning: Docker has an insufficient no. of CPUs 3 - please increase to a minimum of 4 CPUs\n'),
            self.output(stdout_mock))
コード例 #9
0
    def test_docker_insufficient_cpu(self):
        stdout_mock = MagicMock()
        docker_info_mock = MagicMock(
            return_value=b'\nTotal Memory: 3.8 GiB\nCPUs: 1')

        logging_setup.configure_logging(MagicMock(), output=stdout_mock)

        with patch('conductr_cli.terminal.docker_info', docker_info_mock):
            docker.validate_docker_vm(DockerVmType.DOCKER_ENGINE)

        docker_info_mock.assert_called_with()
        self.assertEqual(
            as_warn(
                'Warning: Docker has an insufficient no. of CPUs 1 - please increase to a minimum of 2 CPUs\n'
            ), self.output(stdout_mock))
コード例 #10
0
    def test_docker_insufficient_cpu(self):
        stdout_mock = MagicMock()
        docker_info_mock = MagicMock(
            return_value=b'\nTotal Memory: 3.8 GiB\nCPUs: 3')
        docker_machine_help_mock = MagicMock(
            side_effect=CalledProcessError(-1, 'test only'))

        logging_setup.configure_logging(MagicMock(), output=stdout_mock)
        with patch('conductr_cli.terminal.docker_info', docker_info_mock), \
                patch('conductr_cli.terminal.docker_machine_help', docker_machine_help_mock):
            sandbox_init.init(MagicMock())

        docker_info_mock.assert_called_with()
        self.assertEqual(
            as_warn(
                "Warning: Docker has an insufficient no. of CPUs 3 - please increase to a minimum of 4 CPUs\n"
            ), self.output(stdout_mock))