def unload(args): """`conduct unload` command""" log = logging.getLogger(__name__) path = 'bundles/{}'.format(args.bundle) url = conduct_url.url(path, args) # At the time when this comment is being written, we need to pass the Host header when making HTTP request due to # a bug with requests python library not working properly when IPv6 address is supplied: # https://github.com/kennethreitz/requests/issues/3002 # The workaround for this problem is to explicitly set the Host header when making HTTP request. # This fix is benign and backward compatible as the library would do this when making HTTP request anyway. response = requests.delete(url, timeout=DEFAULT_HTTP_TIMEOUT, headers=conduct_url.request_headers(args)) validation.raise_for_status_inc_3xx(response) if log.is_verbose_enabled(): log.verbose(validation.pretty_json(response.text)) log.info('Bundle unload request sent.') response_json = json.loads(response.text) if not args.no_wait: bundle_installation.wait_for_uninstallation(response_json['bundleId'], args) log.info('Print ConductR info with: conduct info{}'.format( args.cli_parameters)) if not log.is_info_enabled() and log.is_quiet_enabled(): log.quiet(response_json['bundleId']) return True
def test_wait_for_uninstallation(self): count_installations_mock = MagicMock(side_effect=[1, 0]) url_mock = MagicMock(return_value='/bundle-events/endpoint') get_events_mock = MagicMock(return_value=[ create_test_event(None), create_test_event('bundleInstallationRemoved'), create_test_event('bundleInstallationRemoved') ]) stdout = MagicMock() bundle_id = 'a101449418187d92c789d1adc240b6d6' args = MagicMock(**{'wait_timeout': 10}) with patch('conductr_cli.conduct_url.url', url_mock), \ patch('conductr_cli.bundle_installation.count_installations', count_installations_mock), \ patch('conductr_cli.sse_client.get_events', get_events_mock): logging_setup.configure_logging(args, stdout) bundle_installation.wait_for_uninstallation(bundle_id, args) self.assertEqual(count_installations_mock.call_args_list, [call(bundle_id, args), call(bundle_id, args)]) url_mock.assert_called_with('bundles/events', args) self.assertEqual( strip_margin( """|Bundle a101449418187d92c789d1adc240b6d6 waiting to be uninstalled |Bundle a101449418187d92c789d1adc240b6d6 uninstalled |"""), self.output(stdout))
def test_return_immediately_if_uninstalled(self): count_installations_mock = MagicMock(side_effect=[0]) conductr_host = '10.0.0.1' conductr_host_mock = MagicMock(return_value=conductr_host) get_events_mock = MagicMock(return_value=[]) stdout = MagicMock() bundle_id = 'a101449418187d92c789d1adc240b6d6' dcos_mode = True args = MagicMock(**{ 'dcos_mode': dcos_mode, 'wait_timeout': 10, 'conductr_auth': self.conductr_auth, 'server_verification_file': self.server_verification_file }) with patch('conductr_cli.bundle_installation.count_installations', count_installations_mock), \ patch('conductr_cli.conduct_url.conductr_host', conductr_host_mock), \ patch('conductr_cli.sse_client.get_events', get_events_mock): logging_setup.configure_logging(args, stdout) bundle_installation.wait_for_uninstallation(bundle_id, args) self.assertEqual(count_installations_mock.call_args_list, [ call(bundle_id, args) ]) conductr_host_mock.assert_not_called() get_events_mock.assert_not_called() self.assertEqual(strip_margin("""|Bundle a101449418187d92c789d1adc240b6d6 is uninstalled |"""), self.output(stdout))
def unload(args): """`conduct unload` command""" log = logging.getLogger(__name__) path = 'bundles/{}'.format(args.bundle) url = conduct_url.url(path, args) response = conduct_request.delete(args.dcos_mode, conductr_host(args), url, auth=args.conductr_auth, verify=args.server_verification_file, timeout=DEFAULT_HTTP_TIMEOUT) validation.raise_for_status_inc_3xx(response) if log.is_verbose_enabled(): log.verbose(validation.pretty_json(response.text)) log.info('Bundle unload request sent.') response_json = json.loads(response.text) if not args.no_wait: bundle_installation.wait_for_uninstallation(response_json['bundleId'], args) if not args.disable_instructions: log.info('Print ConductR info with: {} info{}'.format( args.command, args.cli_parameters)) if not log.is_info_enabled() and log.is_quiet_enabled(): log.quiet(response_json['bundleId']) return True
def test_wait_for_uninstallation(self): count_installations_mock = MagicMock(side_effect=[1, 0]) url_mock = MagicMock(return_value='/bundle-events/endpoint') get_events_mock = MagicMock(return_value=[ create_test_event(None), create_test_event('bundleInstallationRemoved'), create_test_event('bundleInstallationRemoved') ]) stdout = MagicMock() bundle_id = 'a101449418187d92c789d1adc240b6d6' args = MagicMock(**{ 'wait_timeout': 10 }) with patch('conductr_cli.conduct_url.url', url_mock), \ patch('conductr_cli.bundle_installation.count_installations', count_installations_mock), \ patch('conductr_cli.sse_client.get_events', get_events_mock): logging_setup.configure_logging(args, stdout) bundle_installation.wait_for_uninstallation(bundle_id, args) self.assertEqual(count_installations_mock.call_args_list, [ call(bundle_id, args), call(bundle_id, args) ]) url_mock.assert_called_with('bundles/events', args) self.assertEqual(strip_margin("""|Bundle a101449418187d92c789d1adc240b6d6 waiting to be uninstalled |Bundle a101449418187d92c789d1adc240b6d6 uninstalled |"""), self.output(stdout))
def unload(args): """`conduct unload` command""" log = logging.getLogger(__name__) path = 'bundles/{}'.format(args.bundle) url = conduct_url.url(path, args) response = conduct_request.delete(args.dcos_mode, conductr_host(args), url, auth=args.conductr_auth, verify=args.server_verification_file, timeout=DEFAULT_HTTP_TIMEOUT) validation.raise_for_status_inc_3xx(response) if log.is_verbose_enabled(): log.verbose(validation.pretty_json(response.text)) log.info('Bundle unload request sent.') response_json = json.loads(response.text) if not args.no_wait: bundle_installation.wait_for_uninstallation(response_json['bundleId'], args) if not args.disable_instructions: log.info('Print ConductR info with: {} info{}'.format(args.command, args.cli_parameters)) if not log.is_info_enabled() and log.is_quiet_enabled(): log.quiet(response_json['bundleId']) return True
def unload(args): """`conduct unload` command""" log = logging.getLogger(__name__) path = 'bundles/{}'.format(args.bundle) url = conduct_url.url(path, args) # At the time when this comment is being written, we need to pass the Host header when making HTTP request due to # a bug with requests python library not working properly when IPv6 address is supplied: # https://github.com/kennethreitz/requests/issues/3002 # The workaround for this problem is to explicitly set the Host header when making HTTP request. # This fix is benign and backward compatible as the library would do this when making HTTP request anyway. response = requests.delete(url, timeout=DEFAULT_HTTP_TIMEOUT, headers=conduct_url.request_headers(args)) validation.raise_for_status_inc_3xx(response) if log.is_verbose_enabled(): log.verbose(validation.pretty_json(response.text)) log.info('Bundle unload request sent.') response_json = json.loads(response.text) if not args.no_wait: bundle_installation.wait_for_uninstallation(response_json['bundleId'], args) log.info('Print ConductR info with: conduct info{}'.format(args.cli_parameters)) if not log.is_info_enabled() and log.is_quiet_enabled(): log.quiet(response_json['bundleId']) return True
def test_wait_for_uninstallation(self): count_installations_mock = MagicMock(side_effect=[1, 0]) url_mock = MagicMock(return_value='/bundle-events/endpoint') conductr_host = '10.0.0.1' conductr_host_mock = MagicMock(return_value=conductr_host) get_events_mock = MagicMock(return_value=[ create_heartbeat_event(), create_test_event('bundleInstallationRemoved'), create_test_event('bundleInstallationRemoved') ]) stdout = MagicMock() bundle_id = 'a101449418187d92c789d1adc240b6d6' dcos_mode = True args = MagicMock( **{ 'dcos_mode': dcos_mode, 'wait_timeout': 10, 'conductr_auth': self.conductr_auth, 'server_verification_file': self.server_verification_file }) with patch('conductr_cli.conduct_url.url', url_mock), \ patch('conductr_cli.bundle_installation.count_installations', count_installations_mock), \ patch('conductr_cli.conduct_url.conductr_host', conductr_host_mock), \ patch('conductr_cli.sse_client.get_events', get_events_mock): logging_setup.configure_logging(args, stdout) bundle_installation.wait_for_uninstallation(bundle_id, args) self.assertEqual(count_installations_mock.call_args_list, [call(bundle_id, args), call(bundle_id, args)]) url_mock.assert_called_with('bundles/events', args) conductr_host_mock.assert_called_with(args) get_events_mock.assert_called_with( dcos_mode, conductr_host, '/bundle-events/endpoint', auth=self.conductr_auth, verify=self.server_verification_file) self.assertEqual( strip_margin( """|Bundle a101449418187d92c789d1adc240b6d6 waiting to be uninstalled |Bundle a101449418187d92c789d1adc240b6d6 uninstalled |"""), self.output(stdout))
def test_return_immediately_if_uninstalled(self): count_installations_mock = MagicMock(side_effect=[0]) stdout = MagicMock() bundle_id = 'a101449418187d92c789d1adc240b6d6' args = MagicMock(**{'wait_timeout': 10}) with patch('conductr_cli.bundle_installation.count_installations', count_installations_mock): logging_setup.configure_logging(args, stdout) bundle_installation.wait_for_uninstallation(bundle_id, args) self.assertEqual(count_installations_mock.call_args_list, [call(bundle_id, args)]) self.assertEqual( strip_margin( """|Bundle a101449418187d92c789d1adc240b6d6 is uninstalled |"""), self.output(stdout))
def test_return_immediately_if_uninstalled(self): count_installations_mock = MagicMock(side_effect=[0]) stdout = MagicMock() bundle_id = 'a101449418187d92c789d1adc240b6d6' args = MagicMock(**{ 'wait_timeout': 10 }) with patch('conductr_cli.bundle_installation.count_installations', count_installations_mock): logging_setup.configure_logging(args, stdout) bundle_installation.wait_for_uninstallation(bundle_id, args) self.assertEqual(count_installations_mock.call_args_list, [ call(bundle_id, args) ]) self.assertEqual(strip_margin("""|Bundle a101449418187d92c789d1adc240b6d6 is uninstalled |"""), self.output(stdout))
def test_wait_for_uninstallation(self): count_installations_mock = MagicMock(side_effect=[1, 0]) url_mock = MagicMock(return_value='/bundle-events/endpoint') conductr_host = '10.0.0.1' conductr_host_mock = MagicMock(return_value=conductr_host) get_events_mock = MagicMock(return_value=[ create_heartbeat_event(), create_test_event('bundleInstallationRemoved'), create_test_event('bundleInstallationRemoved') ]) stdout = MagicMock() bundle_id = 'a101449418187d92c789d1adc240b6d6' dcos_mode = True args = MagicMock(**{ 'dcos_mode': dcos_mode, 'wait_timeout': 10, 'conductr_auth': self.conductr_auth, 'server_verification_file': self.server_verification_file }) with patch('conductr_cli.conduct_url.url', url_mock), \ patch('conductr_cli.bundle_installation.count_installations', count_installations_mock), \ patch('conductr_cli.conduct_url.conductr_host', conductr_host_mock), \ patch('conductr_cli.sse_client.get_events', get_events_mock): logging_setup.configure_logging(args, stdout) bundle_installation.wait_for_uninstallation(bundle_id, args) self.assertEqual(count_installations_mock.call_args_list, [ call(bundle_id, args), call(bundle_id, args) ]) url_mock.assert_called_with('bundles/events', args) conductr_host_mock.assert_called_with(args) get_events_mock.assert_called_with(dcos_mode, conductr_host, '/bundle-events/endpoint', auth=self.conductr_auth, verify=self.server_verification_file) self.assertEqual(strip_margin("""|Bundle a101449418187d92c789d1adc240b6d6 waiting to be uninstalled |Bundle a101449418187d92c789d1adc240b6d6 uninstalled |"""), self.output(stdout))