def set_up(self, test_case): test_case.data_path = test_case.makeDir() log_dir = test_case.makeDir() test_case.config_filename = test_case.makeFile( "[client]\n" "url = http://localhost:91919\n" "computer_title = Some Computer\n" "account_name = some_account\n" "ping_url = http://localhost:91910\n" "data_path = %s\n" "log_dir = %s\n" % (test_case.data_path, log_dir)) bootstrap_list.bootstrap(data_path=test_case.data_path, log_dir=log_dir) config = BrokerConfiguration() config.load(["-c", test_case.config_filename]) class FakeBrokerService(BrokerService): reactor_factory = FakeReactor transport_factory = FakeTransport test_case.broker_service = FakeBrokerService(config) test_case.reactor = test_case.broker_service.reactor test_case.remote = FakeRemoteBroker( test_case.broker_service.exchanger, test_case.broker_service.message_store, test_case.broker_service.broker)
def get_data(self): config = BrokerConfiguration() config.load(self.args) # Load the default or specified config tags = config.tags if not is_valid_tag_list(tags): tags = None logging.warning("Invalid tags provided for computer-tags message.") return tags
def test_missing_url_is_defaulted(self): """ Test that if we don't explicitly pass a URL, then this value is defaulted. """ filename = self.makeFile("[client]\n") configuration = BrokerConfiguration() configuration.load(["--config", filename]) self.assertEqual(configuration.url, "https://landscape.canonical.com/message-system")
def test_tag_handling(self): """ The 'tags' value specified in the configuration file is not converted to a list (it must be a string). See bug #1228301. """ filename = self.makeFile("[client]\n" "tags = check,linode,profile-test") configuration = BrokerConfiguration() configuration.load(["--config", filename, "--url", "whatever"]) self.assertEqual(configuration.tags, "check,linode,profile-test")
def test_access_group_handling(self): """ The 'access_group' value specified in the configuration file is passed through. """ filename = self.makeFile("[client]\n" "access_group = webserver") configuration = BrokerConfiguration() configuration.load(["--config", filename, "--url", "whatever"]) self.assertEqual(configuration.access_group, "webserver")
def test_loading_without_http_proxies_does_not_touch_environment(self): """ The L{BrokerConfiguration.load} method doesn't override the 'http_proxy' and 'https_proxy' enviroment variables if they are already set and no new value was specified. """ os.environ["http_proxy"] = "heyo" os.environ["https_proxy"] = "baroo" configuration = BrokerConfiguration() configuration.load(["--url", "whatever"]) self.assertEqual(os.environ["http_proxy"], "heyo") self.assertEqual(os.environ["https_proxy"], "baroo")
def test_intervals_are_ints(self): """ The 'urgent_exchange_interval, 'exchange_interval' and 'ping_interval' values specified in the configuration file are converted to integers. """ filename = self.makeFile("[client]\n" "urgent_exchange_interval = 12\n" "exchange_interval = 34\n" "ping_interval = 6\n") configuration = BrokerConfiguration() configuration.load(["--config", filename, "--url", "whatever"]) self.assertEqual(configuration.urgent_exchange_interval, 12) self.assertEqual(configuration.exchange_interval, 34) self.assertEqual(configuration.ping_interval, 6)
def test_loading_sets_http_proxies(self): """ The L{BrokerConfiguration.load} method sets the 'http_proxy' and 'https_proxy' enviroment variables to the provided values. """ if "http_proxy" in os.environ: del os.environ["http_proxy"] if "https_proxy" in os.environ: del os.environ["https_proxy"] configuration = BrokerConfiguration() configuration.load(["--http-proxy", "foo", "--https-proxy", "bar", "--url", "whatever"]) self.assertEqual(os.environ["http_proxy"], "foo") self.assertEqual(os.environ["https_proxy"], "bar")
def test_loading_resets_http_proxies(self): """ User scenario: Runs landscape-config, fat-fingers a random character into the http_proxy field when he didn't mean to. runs it again, this time leaving it blank. The proxy should be reset to whatever environment-supplied proxy there was at startup. """ os.environ["http_proxy"] = "original" os.environ["https_proxy"] = "originals" configuration = BrokerConfiguration() configuration.load(["--http-proxy", "x", "--https-proxy", "y", "--url", "whatever"]) self.assertEqual(os.environ["http_proxy"], "x") self.assertEqual(os.environ["https_proxy"], "y") configuration.load(["--url", "whatever"]) self.assertEqual(os.environ["http_proxy"], "original") self.assertEqual(os.environ["https_proxy"], "originals")