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 set_up(self, test_case): super(BrokerClientHelper, self).set_up(test_case) # The client needs its own reactor to avoid infinite loops # when the broker broadcasts and event test_case.client_reactor = FakeReactor() config = BrokerConfiguration() config.stagger_launch = 0 # let's keep tests deterministic test_case.client = BrokerClient(test_case.client_reactor, config) test_case.client.broker = test_case.remote
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_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_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_set_intervals(self): """ When a C{set-intervals} message is received, the runtime attributes of the L{MessageExchange} are changed, the configuration values as well, and the configuration is written to disk to be persisted. """ server_message = [{"type": "set-intervals", "urgent-exchange": 1234, "exchange": 5678}] self.transport.responses.append(server_message) self.exchanger.exchange() self.assertEqual(self.config.exchange_interval, 5678) self.assertEqual(self.config.urgent_exchange_interval, 1234) new_config = BrokerConfiguration() new_config.load_configuration_file(self.config_filename) self.assertEqual(new_config.exchange_interval, 5678) self.assertEqual(new_config.urgent_exchange_interval, 1234)
def set_up(self, test_case): data_path = test_case.makeDir() log_dir = test_case.makeDir() test_case.config_filename = os.path.join(test_case.makeDir(), "client.conf") open(test_case.config_filename, "w").write("[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" % (data_path, log_dir)) bootstrap_list.bootstrap(data_path=data_path, log_dir=log_dir) test_case.config = BrokerConfiguration() test_case.config.load(["-c", test_case.config_filename])
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")
def test_default_exchange_intervals(self): """Exchange intervales are set to sane defaults.""" configuration = BrokerConfiguration() self.assertEqual(60, configuration.urgent_exchange_interval) self.assertEqual(900, configuration.exchange_interval)