def base_test_failure_install_timeout(self):
        resolve_bundle_mock = MagicMock(return_value=(self.bundle_name, self.bundle_file))
        http_method = self.respond_with(200, self.default_response)
        stderr = MagicMock()
        open_mock = MagicMock(return_value=1)
        wait_for_installation_mock = MagicMock(side_effect=WaitTimeoutError('test timeout'))

        input_args = MagicMock(**self.default_args)
        with patch('conductr_cli.resolver.resolve_bundle', resolve_bundle_mock), \
                patch('requests.post', http_method), \
                patch('builtins.open', open_mock), \
                patch('conductr_cli.bundle_installation.wait_for_installation', wait_for_installation_mock):
            logging_setup.configure_logging(input_args, err_output=stderr)
            result = conduct_load.load(input_args)
            self.assertFalse(result)

        open_mock.assert_called_with(self.bundle_file, 'rb')
        resolve_bundle_mock.assert_called_with(self.custom_settings, self.bundle_resolve_cache_dir, self.bundle_file)
        http_method.assert_called_with(self.default_url, files=self.default_files, timeout=LOAD_HTTP_TIMEOUT)
        wait_for_installation_mock.assert_called_with(self.bundle_id, input_args)

        self.assertEqual(
            as_error(strip_margin("""|Error: Timed out: test timeout
                                     |""")),
            self.output(stderr))
    def base_test_failure_no_configuration(self):
        resolve_bundle_mock = MagicMock(side_effect=[(self.bundle_name, self.bundle_file),
                                                     BundleResolutionError('some message')])
        stdout = MagicMock()
        stderr = MagicMock()

        with patch('conductr_cli.resolver.resolve_bundle', resolve_bundle_mock):
            args = self.default_args.copy()
            args.update({'configuration': 'no_such.conf'})
            logging_setup.configure_logging(MagicMock(**args), stdout, stderr)
            result = conduct_load.load(MagicMock(**args))
            self.assertFalse(result)

        self.assertEqual(
            resolve_bundle_mock.call_args_list,
            [
                call(self.custom_settings, self.bundle_resolve_cache_dir, self.bundle_file),
                call(self.custom_settings, self.bundle_resolve_cache_dir, 'no_such.conf')
            ]
        )

        self.assertEqual(
            as_error(strip_margin("""|Error: Bundle not found: some message
                                     |""")),
            self.output(stderr))
Ejemplo n.º 3
0
    def base_test_failure_no_response(self):
        resolve_bundle_mock = MagicMock(return_value=(self.bundle_file_name, self.bundle_file))
        create_multipart_mock = MagicMock(return_value=self.multipart_mock)
        http_method = self.raise_read_timeout_error('test reason', self.default_url)
        stdout = MagicMock()
        stderr = MagicMock()
        open_mock = MagicMock(return_value=1)

        input_args = MagicMock(**self.default_args)
        with patch('conductr_cli.resolver.resolve_bundle', resolve_bundle_mock), \
                patch('conductr_cli.conduct_load.create_multipart', create_multipart_mock), \
                patch('requests.post', http_method), \
                patch('builtins.open', open_mock):
            logging_setup.configure_logging(input_args, stdout, stderr)
            result = conduct_load.load(input_args)
            self.assertFalse(result)

        open_mock.assert_called_with(self.bundle_file, 'rb')
        resolve_bundle_mock.assert_called_with(self.custom_settings, self.bundle_resolve_cache_dir, self.bundle_file)
        create_multipart_mock.assert_called_with(self.conduct_load_logger, self.default_files)
        http_method.assert_called_with(self.default_url,
                                       data=self.multipart_mock,
                                       auth=self.conductr_auth,
                                       verify=self.server_verification_file,
                                       headers={'Content-Type': self.multipart_content_type, 'Host': '127.0.0.1'})

        self.assertEqual(
            as_error(
                strip_margin("""|Error: Timed out waiting for response from the server: test reason
                                |Error: One possible issue may be that there are not enough resources or machines with the roles that your bundle requires
                                |""")),
            self.output(stderr))
Ejemplo n.º 4
0
    def test_failure_roles_not_a_list(self):
        stderr = MagicMock()

        tmpdir, bundle_file = create_temp_bundle(
            strip_margin("""|nrOfCpus   = {}
                            |memory     = {}
                            |diskSpace  = {}
                            |roles      = {}
                            |""").format(self.nr_of_cpus, self.memory,
                                         self.disk_space,
                                         '-'.join(self.roles)))

        resolve_bundle_mock = MagicMock(return_value=(self.bundle_file_name,
                                                      bundle_file))
        with patch('conductr_cli.resolver.resolve_bundle',
                   resolve_bundle_mock):
            args = self.default_args.copy()
            args.update({'bundle': bundle_file})
            logging_setup.configure_logging(MagicMock(**args),
                                            err_output=stderr)
            result = conduct_load.load(MagicMock(**args))
            self.assertFalse(result)

        resolve_bundle_mock.assert_called_with(self.custom_settings,
                                               self.bundle_resolve_cache_dir,
                                               bundle_file, self.offline_mode)

        self.assertEqual(
            as_error(
                strip_margin("""|Error: Unable to parse bundle.conf.
                                     |Error: roles has type 'str' rather than 'list'.
                                     |""")), self.output(stderr))

        shutil.rmtree(tmpdir)
Ejemplo n.º 5
0
    def test_warn_bad_oci_image_format_no_tag(self):
        stdout_mock = MagicMock()
        stderr_mock = MagicMock()
        exit_mock = MagicMock()
        configure_logging_mock = MagicMock()
        bndl_main.logging_setup.configure_logging(MagicMock(), stdout_mock,
                                                  stderr_mock)
        temp = tempfile.mkdtemp()

        try:
            with \
                    patch('sys.stdin', MagicMock(**{'buffer': BytesIO(b'')})), \
                    patch('sys.stdout.isatty', lambda: False), \
                    patch('conductr_cli.logging_setup.configure_logging', configure_logging_mock), \
                    patch('sys.exit', exit_mock):
                bndl_main.run([
                    '--name', 'test', '-f', 'oci-image', '-t', 'latest', temp
                ])

            self.assertEqual(self.output(stderr_mock),
                             as_error('Error: bndl: Not an OCI Image\n'))

            exit_mock.assert_called_once_with(2)
        finally:
            shutil.rmtree(temp)
Ejemplo n.º 6
0
    def test_failure_no_disk_space(self):
        stderr = MagicMock()

        tmpdir, bundle_file = create_temp_bundle(
            strip_margin(
                """|nrOfCpus   = {}
                            |memory     = {}
                            |roles      = [{}]
                            |"""
            ).format(self.nr_of_cpus, self.memory, ", ".join(self.roles))
        )

        resolve_bundle_mock = MagicMock(return_value=(self.bundle_file_name, bundle_file))
        with patch("conductr_cli.resolver.resolve_bundle", resolve_bundle_mock):
            args = self.default_args.copy()
            args.update({"bundle": bundle_file})
            logging_setup.configure_logging(MagicMock(**args), err_output=stderr)
            result = conduct_load.load(MagicMock(**args))
            self.assertFalse(result)

        resolve_bundle_mock.assert_called_with(self.custom_settings, self.bundle_resolve_cache_dir, bundle_file)

        self.assertEqual(
            as_error(
                strip_margin(
                    """|Error: Unable to parse bundle.conf.
                                     |Error: No configuration setting found for key diskSpace.
                                     |"""
                )
            ),
            self.output(stderr),
        )

        shutil.rmtree(tmpdir)
    def test_failure_roles_not_a_list(self):
        stderr = MagicMock()

        tmpdir, bundle_file = create_temp_bundle(
            strip_margin("""|nrOfCpus   = {}
                            |memory     = {}
                            |diskSpace  = {}
                            |roles      = {}
                            |""").format(self.nr_of_cpus, self.memory, self.disk_space, '-'.join(self.roles)))

        resolve_bundle_mock = MagicMock(return_value=(self.bundle_name, bundle_file))
        with patch('conductr_cli.resolver.resolve_bundle', resolve_bundle_mock):
            args = self.default_args.copy()
            args.update({'bundle': bundle_file})
            logging_setup.configure_logging(MagicMock(**args), err_output=stderr)
            result = conduct_load.load(MagicMock(**args))
            self.assertFalse(result)

        resolve_bundle_mock.assert_called_with(self.custom_settings, self.bundle_resolve_cache_dir, bundle_file)

        self.assertEqual(
            as_error(strip_margin("""|Error: Unable to parse bundle.conf.
                                     |Error: roles has type 'str' rather than 'list'.
                                     |""")),
            self.output(stderr))

        shutil.rmtree(tmpdir)
Ejemplo n.º 8
0
    def base_test_failure_no_response(self):
        resolve_bundle_mock = MagicMock(return_value=(self.bundle_file_name, self.bundle_file))
        create_multipart_mock = MagicMock(return_value=self.multipart_mock)
        http_method = self.raise_read_timeout_error('test reason', self.default_url)
        stdout = MagicMock()
        stderr = MagicMock()
        open_mock = MagicMock(return_value=1)

        input_args = MagicMock(**self.default_args)
        with patch('conductr_cli.resolver.resolve_bundle', resolve_bundle_mock), \
                patch('conductr_cli.conduct_load.create_multipart', create_multipart_mock), \
                patch('requests.post', http_method), \
                patch('builtins.open', open_mock):
            logging_setup.configure_logging(input_args, stdout, stderr)
            result = conduct_load.load(input_args)
            self.assertFalse(result)

        open_mock.assert_called_with(self.bundle_file, 'rb')
        resolve_bundle_mock.assert_called_with(self.custom_settings, self.bundle_resolve_cache_dir,
                                               self.bundle_file, self.offline_mode)
        create_multipart_mock.assert_called_with(self.conduct_load_logger, self.default_files)
        http_method.assert_called_with(self.default_url,
                                       data=self.multipart_mock,
                                       auth=self.conductr_auth,
                                       verify=self.server_verification_file,
                                       headers={'Content-Type': self.multipart_content_type, 'Host': '127.0.0.1'})

        self.assertEqual(
            as_error(
                strip_margin("""|Error: Timed out waiting for response from the server: test reason
                                |Error: One possible issue may be that there are not enough resources or machines with the roles that your bundle requires
                                |""")),
            self.output(stderr))
Ejemplo n.º 9
0
    def base_test_failure_scale_timeout(self):
        request_headers_mock = MagicMock(return_value=self.mock_headers)
        http_method = self.respond_with(200, self.default_response)
        wait_for_scale_mock = MagicMock(
            side_effect=WaitTimeoutError('test wait timeout error'))
        stderr = MagicMock()

        input_args = MagicMock(**self.default_args)

        with patch('requests.put', http_method), \
                patch('conductr_cli.conduct_url.request_headers', request_headers_mock), \
                patch('conductr_cli.bundle_scale.wait_for_scale', wait_for_scale_mock):
            logging_setup.configure_logging(input_args, err_output=stderr)
            result = conduct_run.run(input_args)
            self.assertFalse(result)

        request_headers_mock.assert_called_with(input_args)
        http_method.assert_called_with(self.default_url,
                                       headers=self.mock_headers)
        wait_for_scale_mock.assert_called_with(self.bundle_id, self.scale,
                                               input_args)

        self.assertEqual(
            as_error(
                strip_margin("""|Error: Timed out: test wait timeout error
                                     |""")), self.output(stderr))
Ejemplo n.º 10
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))
Ejemplo n.º 11
0
    def base_test_failure_bad_zip(self):
        resolve_bundle_mock = MagicMock(return_value=(self.bundle_file_name,
                                                      self.bundle_file))
        stderr = MagicMock()
        bundle_open_mock = MagicMock(
            side_effect=BadZipFile('test bad zip error'))

        with patch('conductr_cli.resolver.resolve_bundle', resolve_bundle_mock), \
                patch('conductr_cli.conduct_load.open_bundle', bundle_open_mock):
            logging_setup.configure_logging(MagicMock(**self.default_args),
                                            err_output=stderr)
            result = conduct_load.load(MagicMock(**self.default_args))
            self.assertFalse(result)

        resolve_bundle_mock.assert_called_with(self.custom_settings,
                                               self.bundle_resolve_cache_dir,
                                               self.bundle_file,
                                               self.offline_mode)
        bundle_open_mock.assert_called_with(
            self.bundle_file_name, self.bundle_file,
            bundle_utils.conf(self.bundle_file))

        self.assertEqual(
            as_error(
                strip_margin(
                    """|Error: Problem with the bundle: test bad zip error
                                     |""")), self.output(stderr))
Ejemplo n.º 12
0
    def test_jvm_validation_java_version_parse_error(self):
        conductr_version = '2.0.0'

        stdout = MagicMock()
        stderr = MagicMock()

        mock_feature = MagicMock()
        features = [mock_feature]
        mock_collect_features = MagicMock(return_value=features)
        mock_sandbox_run_jvm = MagicMock(side_effect=JavaVersionParseError('this is the output from java -version'))

        args = self.default_args.copy()
        args.update({
            'image_version': conductr_version
        })
        input_args = MagicMock(**args)
        with \
                patch('conductr_cli.sandbox_features.collect_features', mock_collect_features), \
                patch('conductr_cli.sandbox_run_jvm.run', mock_sandbox_run_jvm):
            logging_setup.configure_logging(input_args, stdout, stderr)
            self.assertFalse(sandbox_run.run(input_args))

        mock_sandbox_run_jvm.assert_called_once_with(input_args, features)

        expected_output = strip_margin(as_error("""|Error: Unable to obtain java version from the `java -version` command.
                                                   |Error: Please ensure Oracle JVM 1.8 and above is installed.
                                                   |"""))
        self.assertEqual(expected_output, self.output(stderr))
Ejemplo n.º 13
0
    def test_failure_no_bundle_conf(self):
        resolve_bundle_mock = MagicMock(return_value=(self.bundle_file_name,
                                                      self.bundle_file))
        conf_mock = MagicMock(return_value=None)
        stderr = MagicMock()

        with patch('conductr_cli.resolver.resolve_bundle', resolve_bundle_mock), \
                patch('conductr_cli.bundle_utils.conf', conf_mock):
            args = self.default_args.copy()
            logging_setup.configure_logging(MagicMock(**args),
                                            err_output=stderr)
            result = conduct_load.load(MagicMock(**args))
            self.assertFalse(result)

        resolve_bundle_mock.assert_called_with(self.custom_settings,
                                               self.bundle_resolve_cache_dir,
                                               self.bundle_file,
                                               self.offline_mode)

        self.assertEqual(
            as_error(
                strip_margin(
                    """|Error: Problem with the bundle: Unable to find bundle.conf within the bundle file
                                     |""")), self.output(stderr))
        conf_mock.assert_called_with(self.bundle_file)
Ejemplo n.º 14
0
    def base_test_failure_no_configuration(self):
        resolve_bundle_mock = MagicMock(
            side_effect=[(self.bundle_name, self.bundle_file),
                         BundleResolutionError('some message')])
        stdout = MagicMock()
        stderr = MagicMock()

        with patch('conductr_cli.resolver.resolve_bundle',
                   resolve_bundle_mock):
            args = self.default_args.copy()
            args.update({'configuration': 'no_such.conf'})
            logging_setup.configure_logging(MagicMock(**args), stdout, stderr)
            result = conduct_load.load(MagicMock(**args))
            self.assertFalse(result)

        self.assertEqual(resolve_bundle_mock.call_args_list, [
            call(self.custom_settings, self.bundle_resolve_cache_dir,
                 self.bundle_file),
            call(self.custom_settings, self.bundle_resolve_cache_dir,
                 'no_such.conf')
        ])

        self.assertEqual(
            as_error(
                strip_margin("""|Error: Bundle not found: some message
                                     |""")), self.output(stderr))
Ejemplo n.º 15
0
    def base_test_failure(self):
        resolve_bundle_mock = MagicMock(return_value=(self.bundle_file_name, self.bundle_file))
        create_multipart_mock = MagicMock(return_value=self.multipart_mock)
        http_method = self.respond_with(404)
        stdout = MagicMock()
        stderr = MagicMock()
        open_mock = MagicMock(return_value=1)

        input_args = MagicMock(**self.default_args)
        with patch('conductr_cli.resolver.resolve_bundle', resolve_bundle_mock), \
                patch('conductr_cli.conduct_load.create_multipart', create_multipart_mock), \
                patch('requests.post', http_method), \
                patch('builtins.open', open_mock):
            logging_setup.configure_logging(input_args, stdout, stderr)
            result = conduct_load.load(input_args)
            self.assertFalse(result)

        open_mock.assert_called_with(self.bundle_file, 'rb')
        resolve_bundle_mock.assert_called_with(self.custom_settings, self.bundle_resolve_cache_dir, self.bundle_file)
        create_multipart_mock.assert_called_with(self.conduct_load_logger, self.default_files)
        http_method.assert_called_with(self.default_url,
                                       data=self.multipart_mock,
                                       auth=self.conductr_auth,
                                       verify=self.server_verification_file,
                                       headers={'Content-Type': self.multipart_content_type, 'Host': '127.0.0.1'})

        self.assertEqual(
            as_error(strip_margin("""|Error: 404 Not Found
                                     |""")),
            self.output(stderr))
Ejemplo n.º 16
0
    def test_hung_processes(self):
        ps_output = [{
            'id': 58002,
            'type': 'core'
        }, {
            'id': 58003,
            'type': 'agent'
        }]

        stdout = MagicMock()
        stderr = MagicMock()
        mock_os_kill = MagicMock()
        mock_time_sleep = MagicMock()
        mock_find_pids = MagicMock(return_value=ps_output)

        with patch('os.kill', mock_os_kill), \
                patch('time.sleep', mock_time_sleep), \
                patch('conductr_cli.sandbox_common.find_pids', mock_find_pids):
            logging_setup.configure_logging(MagicMock(**self.default_args),
                                            stdout, stderr)
            sandbox_stop_jvm.stop(MagicMock(**self.default_args))

        self.assertEqual(h1('Stopping ConductR') + '\n', self.output(stdout))
        self.assertEqual(
            strip_margin(
                as_error(
                    """|Error: ConductR core pid 58002 could not be stopped
                                                  |Error: ConductR agent pid 58003 could not be stopped
                                                  |Error: Please stop the processes manually
                                                  |""")), self.output(stderr))
        mock_os_kill.assert_has_calls(
            [call(58002, signal.SIGTERM),
             call(58003, signal.SIGTERM)])
Ejemplo n.º 17
0
    def test_error_with_affinity_switch(self):
        args = {
            'host': '127.0.0.1',
            'port': 9005,
            'api_version': '1',
            'verbose': False,
            'no_wait': False,
            'long_ids': False,
            'cli_parameters': '',
            'bundle': self.bundle_id,
            'scale': self.scale,
            'affinity': 'other-bundle'
        }

        stderr = MagicMock()

        logging_setup.configure_logging(MagicMock(**args), err_output=stderr)
        result = conduct_run.run(MagicMock(**args))
        self.assertFalse(result)

        self.assertEqual(
            as_error(
                strip_margin(
                    """|Error: Affinity feature is only available for v1.1 onwards of ConductR
                            |""")), self.output(stderr))
Ejemplo n.º 18
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))
Ejemplo n.º 19
0
    def base_test_failure(self):
        resolve_bundle_mock = MagicMock(return_value=(self.bundle_file_name, self.bundle_file))
        create_multipart_mock = MagicMock(return_value=self.multipart_mock)
        http_method = self.respond_with(404)
        stdout = MagicMock()
        stderr = MagicMock()
        open_mock = MagicMock(return_value=1)

        input_args = MagicMock(**self.default_args)
        with patch('conductr_cli.resolver.resolve_bundle', resolve_bundle_mock), \
                patch('conductr_cli.conduct_load.create_multipart', create_multipart_mock), \
                patch('requests.post', http_method), \
                patch('builtins.open', open_mock):
            logging_setup.configure_logging(input_args, stdout, stderr)
            result = conduct_load.load(input_args)
            self.assertFalse(result)

        open_mock.assert_called_with(self.bundle_file, 'rb')
        resolve_bundle_mock.assert_called_with(self.custom_settings, self.bundle_resolve_cache_dir,
                                               self.bundle_file, self.offline_mode)
        create_multipart_mock.assert_called_with(self.conduct_load_logger, self.default_files)
        http_method.assert_called_with(self.default_url,
                                       data=self.multipart_mock,
                                       auth=self.conductr_auth,
                                       verify=self.server_verification_file,
                                       headers={'Content-Type': self.multipart_content_type, 'Host': '127.0.0.1'})

        self.assertEqual(
            as_error(strip_margin("""|Error: 404 Not Found
                                     |""")),
            self.output(stderr))
Ejemplo n.º 20
0
    def base_test_failure(self):
        request_headers_mock = MagicMock(return_value=self.mock_headers)
        resolve_bundle_mock = MagicMock(return_value=(self.bundle_name,
                                                      self.bundle_file))
        http_method = self.respond_with(404)
        stdout = MagicMock()
        stderr = MagicMock()
        open_mock = MagicMock(return_value=1)

        input_args = MagicMock(**self.default_args)
        with patch('conductr_cli.resolver.resolve_bundle', resolve_bundle_mock), \
                patch('conductr_cli.conduct_url.request_headers', request_headers_mock), \
                patch('requests.post', http_method), \
                patch('builtins.open', open_mock):
            logging_setup.configure_logging(input_args, stdout, stderr)
            result = conduct_load.load(input_args)
            self.assertFalse(result)

        open_mock.assert_called_with(self.bundle_file, 'rb')
        resolve_bundle_mock.assert_called_with(self.custom_settings,
                                               self.bundle_resolve_cache_dir,
                                               self.bundle_file)
        request_headers_mock.assert_called_with(input_args)
        http_method.assert_called_with(self.default_url,
                                       files=self.default_files,
                                       timeout=LOAD_HTTP_TIMEOUT,
                                       headers=self.mock_headers)

        self.assertEqual(
            as_error(
                strip_margin("""|Error: 404 Not Found
                                     |""")), self.output(stderr))
Ejemplo n.º 21
0
    def base_test_failure_install_timeout(self):
        resolve_bundle_mock = MagicMock(return_value=(self.bundle_file_name, self.bundle_file))
        create_multipart_mock = MagicMock(return_value=self.multipart_mock)
        http_method = self.respond_with(200, self.default_response)
        stderr = MagicMock()
        open_mock = MagicMock(return_value=1)
        wait_for_installation_mock = MagicMock(side_effect=WaitTimeoutError('test timeout'))

        input_args = MagicMock(**self.default_args)
        with patch('conductr_cli.resolver.resolve_bundle', resolve_bundle_mock), \
                patch('conductr_cli.conduct_load.create_multipart', create_multipart_mock), \
                patch('requests.post', http_method), \
                patch('builtins.open', open_mock), \
                patch('conductr_cli.bundle_installation.wait_for_installation', wait_for_installation_mock):
            logging_setup.configure_logging(input_args, err_output=stderr)
            result = conduct_load.load(input_args)
            self.assertFalse(result)

        open_mock.assert_called_with(self.bundle_file, 'rb')
        create_multipart_mock.assert_called_with(self.conduct_load_logger, self.default_files)
        http_method.assert_called_with(self.default_url,
                                       data=self.multipart_mock,
                                       auth=self.conductr_auth,
                                       verify=self.server_verification_file,
                                       headers={'Content-Type': self.multipart_content_type, 'Host': '127.0.0.1'})
        wait_for_installation_mock.assert_called_with(self.bundle_id, input_args)

        self.assertEqual(
            as_error(strip_margin("""|Error: Timed out: test timeout
                                     |""")),
            self.output(stderr))
Ejemplo n.º 22
0
    def base_test_failure_no_response(self):
        request_headers_mock = MagicMock(return_value=self.mock_headers)
        resolve_bundle_mock = MagicMock(return_value=(self.bundle_name,
                                                      self.bundle_file))
        http_method = self.raise_read_timeout_error('test reason',
                                                    self.default_url)
        stdout = MagicMock()
        stderr = MagicMock()
        open_mock = MagicMock(return_value=1)

        input_args = MagicMock(**self.default_args)
        with patch('conductr_cli.resolver.resolve_bundle', resolve_bundle_mock), \
                patch('conductr_cli.conduct_url.request_headers', request_headers_mock), \
                patch('requests.post', http_method), \
                patch('builtins.open', open_mock):
            logging_setup.configure_logging(input_args, stdout, stderr)
            result = conduct_load.load(input_args)
            self.assertFalse(result)

        open_mock.assert_called_with(self.bundle_file, 'rb')
        resolve_bundle_mock.assert_called_with(self.custom_settings,
                                               self.bundle_resolve_cache_dir,
                                               self.bundle_file)
        request_headers_mock.assert_called_with(input_args)
        http_method.assert_called_with(self.default_url,
                                       files=self.default_files,
                                       timeout=LOAD_HTTP_TIMEOUT,
                                       headers=self.mock_headers)

        self.assertEqual(
            as_error(
                strip_margin(
                    """|Error: Timed out waiting for response from the server: test reason
                                |Error: One possible issue may be that there are not enough resources or machines with the roles that your bundle requires
                                |""")), self.output(stderr))
Ejemplo n.º 23
0
    def base_test_failure_install_timeout(self):
        resolve_bundle_mock = MagicMock(return_value=(self.bundle_file_name, self.bundle_file))
        create_multipart_mock = MagicMock(return_value=self.multipart_mock)
        http_method = self.respond_with(200, self.default_response)
        stderr = MagicMock()
        open_mock = MagicMock(return_value=1)
        wait_for_installation_mock = MagicMock(side_effect=WaitTimeoutError('test timeout'))

        input_args = MagicMock(**self.default_args)
        with patch('conductr_cli.resolver.resolve_bundle', resolve_bundle_mock), \
                patch('conductr_cli.conduct_load.create_multipart', create_multipart_mock), \
                patch('requests.post', http_method), \
                patch('builtins.open', open_mock), \
                patch('conductr_cli.bundle_installation.wait_for_installation', wait_for_installation_mock):
            logging_setup.configure_logging(input_args, err_output=stderr)
            result = conduct_load.load(input_args)
            self.assertFalse(result)

        open_mock.assert_called_with(self.bundle_file, 'rb')
        create_multipart_mock.assert_called_with(self.conduct_load_logger, self.default_files)
        http_method.assert_called_with(self.default_url,
                                       data=self.multipart_mock,
                                       auth=self.conductr_auth,
                                       verify=self.server_verification_file,
                                       headers={'Content-Type': self.multipart_content_type, 'Host': '127.0.0.1'})
        wait_for_installation_mock.assert_called_with(self.bundle_id, input_args)

        self.assertEqual(
            as_error(strip_margin("""|Error: Timed out: test timeout
                                     |""")),
            self.output(stderr))
Ejemplo n.º 24
0
    def base_test_failure_scale_timeout(self):
        http_method = self.respond_with(200, self.default_response)
        wait_for_scale_mock = MagicMock(
            side_effect=WaitTimeoutError('test wait timeout error'))
        stderr = MagicMock()

        input_args = MagicMock(**self.default_args)

        with patch('requests.put', http_method), \
                patch('conductr_cli.bundle_scale.wait_for_scale', wait_for_scale_mock):
            logging_setup.configure_logging(input_args, err_output=stderr)
            result = conduct_run.run(input_args)
            self.assertFalse(result)

        http_method.assert_called_with(self.default_url,
                                       auth=self.conductr_auth,
                                       verify=self.server_verification_file,
                                       headers={'Host': '127.0.0.1'})
        wait_for_scale_mock.assert_called_with(self.bundle_id,
                                               self.scale,
                                               wait_for_is_active=True,
                                               args=input_args)

        self.assertEqual(
            as_error(
                strip_margin("""|Error: Timed out: test wait timeout error
                                     |""")), self.output(stderr))
Ejemplo n.º 25
0
    def test_warn_bad_oci_image_format_no_layout(self):
        stdout_mock = MagicMock()
        stderr_mock = MagicMock()
        exit_mock = MagicMock()
        configure_logging_mock = MagicMock()
        bndl_main.logging_setup.configure_logging(MagicMock(), stdout_mock,
                                                  stderr_mock)
        temp = tempfile.mkdtemp()

        try:
            os.mkdir(os.path.join(temp, 'refs'))
            open(os.path.join(temp, 'refs/latest'), 'a').close()

            with \
                    patch('sys.stdin', MagicMock(**{'buffer': BytesIO(b'')})), \
                    patch('sys.stdout.isatty', lambda: False), \
                    patch('conductr_cli.logging_setup.configure_logging', configure_logging_mock), \
                    patch('sys.exit', exit_mock):
                bndl_main.run([
                    '--name', 'test', '-f', 'oci-image', '-t', 'latest', temp
                ])

            self.assertEqual(
                self.output(stderr_mock),
                as_error(
                    'Error: bndl: Invalid OCI Image. Missing oci-layout\n'))

            exit_mock.assert_called_once_with(2)
        finally:
            shutil.rmtree(temp)
    def test_cannot_stop_containers(self):
        stdout = MagicMock()
        stderr = MagicMock()
        mock_docker_rm = MagicMock(
            side_effect=CalledProcessError(-1, 'test only'))
        containers = ['cond-0', 'cond-1']

        with patch('conductr_cli.sandbox_common.resolve_running_docker_containers', return_value=containers), \
                patch('conductr_cli.terminal.docker_rm', mock_docker_rm):
            logging_setup.configure_logging(MagicMock(**self.default_args),
                                            stdout, stderr)
            sandbox_stop_docker.stop(MagicMock(**self.default_args))

        self.assertEqual(
            strip_margin("""||------------------------------------------------|
                                         || Stopping ConductR                              |
                                         ||------------------------------------------------|
                                         |"""), self.output(stdout))
        self.assertEqual(
            as_error(
                strip_margin(
                    """|Error: ConductR containers could not be stopped
                                     |Error: Please stop the Docker containers manually
                                     |""")), self.output(stderr))
        mock_docker_rm.assert_called_once_with(containers)
Ejemplo n.º 27
0
    def test_no_ref(self):
        tmpdir = tempfile.mkdtemp()

        with tempfile.NamedTemporaryFile() as output:
            attributes = create_attributes_object({
                'name': 'test',
                'source': tmpdir,
                'format': 'oci-image',
                'tag': 'latest',
                'output': output.name
            })

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

        os.mkdir(os.path.join(tmpdir, 'refs'))
        open(os.path.join(tmpdir, 'oci-layout'), 'w').close()

        with \
                patch('sys.stdin', MagicMock(**{'buffer': BytesIO(b'')})), \
                patch('sys.stdout.buffer.write', stdout_mock):
            bndl_create.bndl_create(attributes)

        self.assertEqual(
            self.output(stderr_mock),
            as_error(
                'Error: bndl: Invalid OCI Image. Cannot find requested tag "latest" in OCI Image\n'
            ))
Ejemplo n.º 28
0
    def test_file_not_found_error(self):
        args = MagicMock()
        stderr = MagicMock()
        _mock_open = MagicMock(side_effect=FileNotFoundError)

        with patch('builtins.open', _mock_open):
            logging_setup.configure_logging(args, err_output=stderr)
            self.assertFalse(sandbox_restart.restart(args))
            self.assertEqual(
                as_error(
                    strip_margin("""|Error: ConductR cannot be restarted.
                                                      |Error: Please start ConductR first with: sandbox run
                                                      |""")),
                self.output(stderr))
Ejemplo n.º 29
0
    def test_failure(self):
        http_method = self.respond_with(404)
        stderr = MagicMock()

        with patch('requests.put', http_method):
            logging_setup.configure_logging(MagicMock(**self.default_args), err_output=stderr)
            result = conduct_stop.stop(MagicMock(**self.default_args))
            self.assertFalse(result)

        http_method.assert_called_with(self.default_url, timeout=DEFAULT_HTTP_TIMEOUT)

        self.assertEqual(
            as_error(strip_margin("""|Error: 404 Not Found
                                     |""")),
            self.output(stderr))
Ejemplo n.º 30
0
    def base_test_failure_no_file_url_error(self):
        resolve_bundle_mock = MagicMock(side_effect=URLError('reason', None))
        stderr = MagicMock()

        with patch('conductr_cli.resolver.resolve_bundle', resolve_bundle_mock):
            logging_setup.configure_logging(MagicMock(**self.default_args), err_output=stderr)
            result = conduct_load.load(MagicMock(**self.default_args))
            self.assertFalse(result)

        resolve_bundle_mock.assert_called_with(self.custom_settings, self.bundle_resolve_cache_dir, self.bundle_file)

        self.assertEqual(
            as_error(strip_margin("""|Error: File not found: reason
                                     |""")),
            self.output(stderr))
Ejemplo n.º 31
0
    def base_test_failure_no_file_url_error(self):
        resolve_bundle_mock = MagicMock(side_effect=URLError('reason', None))
        stderr = MagicMock()

        with patch('conductr_cli.resolver.resolve_bundle', resolve_bundle_mock):
            logging_setup.configure_logging(MagicMock(**self.default_args), err_output=stderr)
            result = conduct_load.load(MagicMock(**self.default_args))
            self.assertFalse(result)

        resolve_bundle_mock.assert_called_with(self.custom_settings, self.bundle_resolve_cache_dir,
                                               self.bundle_file, self.offline_mode)

        self.assertEqual(
            as_error(strip_margin("""|Error: File not found: reason
                                     |""")),
            self.output(stderr))
Ejemplo n.º 32
0
    def base_test_failure_no_file_http_error(self):
        add_info_mock = MagicMock()
        resolve_bundle_mock = MagicMock(side_effect=HTTPError('url', 'code', 'message', 'headers', add_info_mock))
        stderr = MagicMock()

        with patch('conductr_cli.resolver.resolve_bundle', resolve_bundle_mock):
            logging_setup.configure_logging(MagicMock(**self.default_args), err_output=stderr)
            result = conduct_load.load(MagicMock(**self.default_args))
            self.assertFalse(result)

        resolve_bundle_mock.assert_called_with(self.custom_settings, self.bundle_resolve_cache_dir, self.bundle_file)

        self.assertEqual(
            as_error(strip_margin("""|Error: Resource not found: url
                                     |""")),
            self.output(stderr))
Ejemplo n.º 33
0
    def base_test_failure_no_file_http_error(self):
        add_info_mock = MagicMock()
        resolve_bundle_mock = MagicMock(side_effect=HTTPError('url', 'code', 'message', 'headers', add_info_mock))
        stderr = MagicMock()

        with patch('conductr_cli.resolver.resolve_bundle', resolve_bundle_mock):
            logging_setup.configure_logging(MagicMock(**self.default_args), err_output=stderr)
            result = conduct_load.load(MagicMock(**self.default_args))
            self.assertFalse(result)

        resolve_bundle_mock.assert_called_with(self.custom_settings, self.bundle_resolve_cache_dir,
                                               self.bundle_file, self.offline_mode)

        self.assertEqual(
            as_error(strip_margin("""|Error: Resource not found: url
                                     |""")),
            self.output(stderr))
Ejemplo n.º 34
0
    def test_failure(self):
        http_method = self.respond_with(404)
        stderr = MagicMock()

        input_args = MagicMock(**self.default_args)
        with patch('requests.delete', http_method):
            logging_setup.configure_logging(input_args, err_output=stderr)
            result = conduct_unload.unload(input_args)
            self.assertFalse(result)

        http_method.assert_called_with(self.default_url, auth=self.conductr_auth, verify=self.server_verification_file,
                                       timeout=DEFAULT_HTTP_TIMEOUT, headers={'Host': '127.0.0.1'})

        self.assertEqual(
            as_error(strip_margin("""|Error: 404 Not Found
                                     |""")),
            self.output(stderr))
Ejemplo n.º 35
0
    def test_warn_tar_output_tty(self):
        stdout = MagicMock()
        stderr = MagicMock()
        logging_setup.configure_logging(MagicMock(), stdout, stderr)

        configure_logging_mock = MagicMock()

        with \
                patch('sys.stdout.isatty', lambda: True), \
                patch('sys.stdin.isatty', lambda: True), \
                patch('conductr_cli.logging_setup.configure_logging', configure_logging_mock), \
                patch('sys.exit', lambda _: ()):
            run(['--tar', 'test.tar'])

        self.assertEqual(
            self.output(stderr),
            as_error('Error: shazar: Refusing to write to terminal. Provide -o or redirect elsewhere\n')
        )
Ejemplo n.º 36
0
    def base_test_failure_bad_zip(self):
        resolve_bundle_mock = MagicMock(return_value=(self.bundle_file_name, self.bundle_file))
        stderr = MagicMock()
        open_mock = MagicMock(side_effect=BadZipFile('test bad zip error'))

        with patch('conductr_cli.resolver.resolve_bundle', resolve_bundle_mock), \
                patch('builtins.open', open_mock):
            logging_setup.configure_logging(MagicMock(**self.default_args), err_output=stderr)
            result = conduct_load.load(MagicMock(**self.default_args))
            self.assertFalse(result)

        resolve_bundle_mock.assert_called_with(self.custom_settings, self.bundle_resolve_cache_dir, self.bundle_file)
        open_mock.assert_called_with(self.bundle_file, 'rb')

        self.assertEqual(
            as_error(strip_margin("""|Error: Problem with the bundle: test bad zip error
                                     |""")),
            self.output(stderr))
Ejemplo n.º 37
0
    def test_failure_stop_timeout(self):
        http_method = self.respond_with(200, self.default_response)
        wait_for_scale_mock = MagicMock(side_effect=WaitTimeoutError('test timeout error'))
        stderr = MagicMock()

        input_args = MagicMock(**self.default_args)
        with patch('requests.put', http_method), \
                patch('conductr_cli.bundle_scale.wait_for_scale', wait_for_scale_mock):
            logging_setup.configure_logging(input_args, err_output=stderr)
            result = conduct_stop.stop(input_args)
            self.assertFalse(result)

        http_method.assert_called_with(self.default_url, timeout=DEFAULT_HTTP_TIMEOUT)
        wait_for_scale_mock.assert_called_with(self.bundle_id, 0, input_args)

        self.assertEqual(
            as_error(strip_margin("""|Error: Timed out: test timeout error
                                     |""")),
            self.output(stderr))
    def base_test_failure(self):
        request_headers_mock = MagicMock(return_value=self.mock_headers)
        http_method = self.respond_with(404)
        stderr = MagicMock()

        input_args = MagicMock(**self.default_args)
        with patch('requests.put', http_method), \
                patch('conductr_cli.conduct_url.request_headers', request_headers_mock):
            logging_setup.configure_logging(input_args, err_output=stderr)
            result = conduct_run.run(input_args)
            self.assertFalse(result)

        request_headers_mock.assert_called_with(input_args)
        http_method.assert_called_with(self.default_url, headers=self.mock_headers)

        self.assertEqual(
            as_error(strip_margin("""|Error: 404 Not Found
                                     |""")),
            self.output(stderr))
    def test_failure_no_bundle_conf(self):
        resolve_bundle_mock = MagicMock(return_value=(self.bundle_name, self.bundle_file))
        zip_entry_mock = MagicMock(return_value=None)
        stderr = MagicMock()

        with patch('conductr_cli.resolver.resolve_bundle', resolve_bundle_mock), \
                patch('conductr_cli.bundle_utils.zip_entry', zip_entry_mock):
            args = self.default_args.copy()
            logging_setup.configure_logging(MagicMock(**args), err_output=stderr)
            result = conduct_load.load(MagicMock(**args))
            self.assertFalse(result)

        resolve_bundle_mock.assert_called_with(self.custom_settings, self.bundle_resolve_cache_dir, self.bundle_file)

        self.assertEqual(
            as_error(strip_margin("""|Error: Problem with the bundle: Unable to find bundle.conf within the bundle file
                                     |""")),
            self.output(stderr))
        zip_entry_mock.assert_called_with('bundle.conf', self.bundle_file)
Ejemplo n.º 40
0
    def test_no_vm_found(self):
        stdout_mock = MagicMock()
        logging_setup.configure_logging(MagicMock(), err_output=stdout_mock)

        with self.assertRaises(SystemExit) as exit:
            sandbox_main.validate_docker_vm(DockerVmType.NONE)

        self.assertEqual(
            as_error(strip_margin(
                """|Error: Neither Docker native is installed nor the Docker machine environment variables are set.
                   |Error: We recommend to use one of following the Docker distributions depending on your OS:
                   |Error:   Linux:                                         Docker Engine
                   |Error:   MacOS:                                         Docker for Mac
                   |Error:   Windows 10+ Professional or Enterprise 64-bit: Docker for Windows
                   |Error:   Other Windows:                                 Docker machine via Docker Toolbox
                   |Error: For more information checkout: https://www.docker.com/products/overview
                   |""")),
            self.output(stdout_mock))
        self.assertEqual(exit.exception.code, 1)
Ejemplo n.º 41
0
    def base_test_failure(self):
        http_method = self.respond_with(404)
        stderr = MagicMock()

        input_args = MagicMock(**self.default_args)
        with patch('requests.put', http_method):
            logging_setup.configure_logging(input_args, err_output=stderr)
            result = conduct_run.run(input_args)
            self.assertFalse(result)

        http_method.assert_called_with(self.default_url,
                                       auth=self.conductr_auth,
                                       verify=self.server_verification_file,
                                       headers={'Host': '127.0.0.1'})

        self.assertEqual(
            as_error(
                strip_margin("""|Error: 404 Not Found
                                     |""")), self.output(stderr))
Ejemplo n.º 42
0
    def base_test_failure(self):
        request_headers_mock = MagicMock(return_value=self.mock_headers)
        http_method = self.respond_with(404)
        stderr = MagicMock()

        input_args = MagicMock(**self.default_args)
        with patch('requests.put', http_method), \
                patch('conductr_cli.conduct_url.request_headers', request_headers_mock):
            logging_setup.configure_logging(input_args, err_output=stderr)
            result = conduct_run.run(input_args)
            self.assertFalse(result)

        request_headers_mock.assert_called_with(input_args)
        http_method.assert_called_with(self.default_url,
                                       headers=self.mock_headers)

        self.assertEqual(
            as_error(
                strip_margin("""|Error: 404 Not Found
                                     |""")), self.output(stderr))
Ejemplo n.º 43
0
    def base_test_failure_scale_timeout(self):
        http_method = self.respond_with(200, self.default_response)
        wait_for_scale_mock = MagicMock(side_effect=WaitTimeoutError('test wait timeout error'))
        stderr = MagicMock()

        input_args = MagicMock(**self.default_args)

        with patch('requests.put', http_method), \
                patch('conductr_cli.bundle_scale.wait_for_scale', wait_for_scale_mock):
            logging_setup.configure_logging(input_args, err_output=stderr)
            result = conduct_run.run(input_args)
            self.assertFalse(result)

        http_method.assert_called_with(self.default_url, auth=self.conductr_auth, verify=self.server_verification_file,
                                       headers={'Host': '127.0.0.1'})
        wait_for_scale_mock.assert_called_with(self.bundle_id, self.scale, input_args)

        self.assertEqual(
            as_error(strip_margin("""|Error: Timed out: test wait timeout error
                                     |""")),
            self.output(stderr))
Ejemplo n.º 44
0
    def test_should_display_error_only(self):
        stdout = MagicMock()
        stderr = MagicMock()
        logging_setup.configure_logging(MagicMock(), stdout, stderr)

        log = logging.getLogger()
        log.debug('this is debug')
        log.verbose('this is verbose')
        log.info('this is info')
        log.quiet('this is quiet')
        log.warning('this is warning')
        log.error('this is error')

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

        self.assertEqual('', self.output(stdout))
        self.assertEqual(as_error('Error: this is error\n'), self.output(stderr))
    def base_test_failure(self):
        resolve_bundle_mock = MagicMock(return_value=(self.bundle_name, self.bundle_file))
        http_method = self.respond_with(404)
        stdout = MagicMock()
        stderr = MagicMock()
        open_mock = MagicMock(return_value=1)

        with patch('conductr_cli.resolver.resolve_bundle', resolve_bundle_mock), \
                patch('requests.post', http_method), \
                patch('builtins.open', open_mock):
            logging_setup.configure_logging(MagicMock(**self.default_args), stdout, stderr)
            result = conduct_load.load(MagicMock(**self.default_args))
            self.assertFalse(result)

        open_mock.assert_called_with(self.bundle_file, 'rb')
        resolve_bundle_mock.assert_called_with(self.custom_settings, self.bundle_resolve_cache_dir, self.bundle_file)
        http_method.assert_called_with(self.default_url, files=self.default_files, timeout=LOAD_HTTP_TIMEOUT)

        self.assertEqual(
            as_error(strip_margin("""|Error: 404 Not Found
                                     |""")),
            self.output(stderr))
Ejemplo n.º 46
0
    def test_no_format(self):
        attributes = create_attributes_object({
            'source': None,
            'format': None,
            'tag': 'latest',
            'output': None
        })

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

        with \
                patch('sys.stdin', MagicMock(**{'buffer': BytesIO(b'')})), \
                patch('sys.stdout.buffer.write', stdout_mock):
            bndl_create.bndl_create(attributes)

        self.assertEqual(
            self.output(stderr_mock),
            as_error(
                'Error: bndl: Unable to detect format. Provide a -f or --format argument\n'
            ))
Ejemplo n.º 47
0
    def test_warn_output_tty(self):
        stdout_mock = MagicMock()
        stderr_mock = MagicMock()
        exit_mock = MagicMock()
        configure_logging_mock = MagicMock()
        bndl_main.logging_setup.configure_logging(MagicMock(), stdout_mock,
                                                  stderr_mock)

        with \
                patch('sys.stdin', MagicMock(**{'buffer': BytesIO(b''), 'isatty': MagicMock(return_value=False)})), \
                patch('sys.stdout.isatty', lambda: True), \
                patch('conductr_cli.logging_setup.configure_logging', configure_logging_mock), \
                patch('sys.exit', exit_mock):
            bndl_main.run(['--name', 'test', '--tag', 'latest'])

        self.assertEqual(
            self.output(stderr_mock),
            as_error(
                'Error: bndl: Refusing to write to terminal. Provide -o or redirect elsewhere\n'
            ))

        exit_mock.assert_called_once_with(2)
Ejemplo n.º 48
0
    def test_bndl_oci_image_missing_args(self):
        stdout_mock = MagicMock()
        stderr_mock = MagicMock()
        exit_mock = MagicMock()
        configure_logging_mock = MagicMock()
        bndl_main.logging_setup.configure_logging(MagicMock(), stdout_mock,
                                                  stderr_mock)

        with \
                patch('sys.stdin', MagicMock(**{'buffer': BytesIO(b'')})), \
                patch('sys.stdout.isatty', lambda: False), \
                patch('conductr_cli.logging_setup.configure_logging', configure_logging_mock), \
                patch('sys.exit', exit_mock):
            bndl_main.run(['-f', 'oci-image'])

        self.assertEqual(
            self.output(stderr_mock),
            as_error(
                'Error: bndl: OCI Image support requires that you provide a --name argument\n'
            ))

        exit_mock.assert_called_once_with(2)
Ejemplo n.º 49
0
    def test_warn_bad_file(self):
        stdout_mock = MagicMock()
        stderr_mock = MagicMock()
        exit_mock = MagicMock()
        configure_logging_mock = MagicMock()
        bndl_main.logging_setup.configure_logging(MagicMock(), stdout_mock,
                                                  stderr_mock)

        with \
                patch('sys.stdin', MagicMock(**{'buffer': BytesIO(b'')})), \
                patch('sys.stdout.isatty', lambda: False), \
                patch('conductr_cli.logging_setup.configure_logging', configure_logging_mock), \
                patch('sys.exit', exit_mock):
            bndl_main.run(['--name', 'test', '-f', 'docker', '/some/file'])

        self.assertEqual(
            self.output(stderr_mock),
            as_error(
                'Error: bndl: Unable to read /some/file. Must be the path to a valid file or directory\n'
            ))

        exit_mock.assert_called_once_with(2)
Ejemplo n.º 50
0
    def test_should_display_error_only(self):
        stdout = MagicMock()
        stderr = MagicMock()
        logging_setup.configure_logging(MagicMock(), stdout, stderr)

        log = logging.getLogger()
        log.debug('this is debug')
        log.verbose('this is verbose')
        log.info('this is info')
        log.quiet('this is quiet')
        log.warning('this is warning')
        log.error('this is error')

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

        self.assertEqual('', self.output(stdout))
        self.assertEqual(as_error('Error: this is error\n'),
                         self.output(stderr))
Ejemplo n.º 51
0
    def test_docker_not_running(self):
        stdout_mock = MagicMock()
        docker_info_mock = MagicMock(side_effect=CalledProcessError(-1, 'test only'))

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

        with \
                patch('conductr_cli.terminal.docker_info', docker_info_mock), \
                self.assertRaises(SystemExit) as exit:
            sandbox_main.validate_docker_vm(DockerVmType.DOCKER_ENGINE)

        docker_info_mock.assert_called_with()
        self.assertEqual(
            as_error(strip_margin(
                """|Error: Docker native is installed but not running.
                   |Error: Please start Docker with one of the Docker flavors based on your OS:
                   |Error:   Linux:   Docker service
                   |Error:   MacOS:   Docker for Mac
                   |Error:   Windows: Docker for Windows
                   |Error: A successful Docker startup can be verified with: docker info
                   |""")),
            self.output(stdout_mock))
        self.assertEqual(exit.exception.code, 1)
    def base_test_failure_scale_timeout(self):
        request_headers_mock = MagicMock(return_value=self.mock_headers)
        http_method = self.respond_with(200, self.default_response)
        wait_for_scale_mock = MagicMock(side_effect=WaitTimeoutError('test wait timeout error'))
        stderr = MagicMock()

        input_args = MagicMock(**self.default_args)

        with patch('requests.put', http_method), \
                patch('conductr_cli.conduct_url.request_headers', request_headers_mock), \
                patch('conductr_cli.bundle_scale.wait_for_scale', wait_for_scale_mock):
            logging_setup.configure_logging(input_args, err_output=stderr)
            result = conduct_run.run(input_args)
            self.assertFalse(result)

        request_headers_mock.assert_called_with(input_args)
        http_method.assert_called_with(self.default_url, headers=self.mock_headers)
        wait_for_scale_mock.assert_called_with(self.bundle_id, self.scale, input_args)

        self.assertEqual(
            as_error(strip_margin("""|Error: Timed out: test wait timeout error
                                     |""")),
            self.output(stderr))
    def base_test_failure_no_response(self):
        resolve_bundle_mock = MagicMock(return_value=(self.bundle_name, self.bundle_file))
        http_method = self.raise_read_timeout_error('test reason', self.default_url)
        stdout = MagicMock()
        stderr = MagicMock()
        open_mock = MagicMock(return_value=1)

        with patch('conductr_cli.resolver.resolve_bundle', resolve_bundle_mock), \
                patch('requests.post', http_method), \
                patch('builtins.open', open_mock):
            logging_setup.configure_logging(MagicMock(**self.default_args), stdout, stderr)
            result = conduct_load.load(MagicMock(**self.default_args))
            self.assertFalse(result)

        open_mock.assert_called_with(self.bundle_file, 'rb')
        resolve_bundle_mock.assert_called_with(self.custom_settings, self.bundle_resolve_cache_dir, self.bundle_file)
        http_method.assert_called_with(self.default_url, files=self.default_files, timeout=LOAD_HTTP_TIMEOUT)

        self.assertEqual(
            as_error(
                strip_margin("""|Error: Timed out waiting for response from the server: test reason
                                |Error: One possible issue may be that there are not enough resources or machines with the roles that your bundle requires
                                |""")),
            self.output(stderr))
Ejemplo n.º 54
0
    def test_error_with_affinity_switch(self):
        args = {
            'host': '127.0.0.1',
            'port': 9005,
            'api_version': '1',
            'verbose': False,
            'no_wait': False,
            'long_ids': False,
            'cli_parameters': '',
            'bundle': self.bundle_id,
            'scale': self.scale,
            'affinity': 'other-bundle'
        }

        stderr = MagicMock()

        logging_setup.configure_logging(MagicMock(**args), err_output=stderr)
        result = conduct_run.run(MagicMock(**args))
        self.assertFalse(result)

        self.assertEqual(
            as_error(strip_margin("""|Error: Affinity feature is only available for v1.1 onwards of ConductR
                            |""")),
            self.output(stderr))