def test_checks_log_collector_mode(self): # Specify full mode c, f, v, d, cfp, lcm, _ = parse_args(["-collect-logs", "-full"]) # pylint: disable=unused-variable self.assertEqual(c, "collect-logs") self.assertEqual(lcm, True) # Defaults to None if mode not specified c, f, v, d, cfp, lcm, _ = parse_args(["-collect-logs"]) # pylint: disable=unused-variable self.assertEqual(c, "collect-logs") self.assertEqual(lcm, False)
def test_rejects_missing_configuration_path(self, mock_exit, mock_exists, mock_stderr): try: c, f, v, d, cfp = parse_args(["-configuration-path:/foo/bar.conf"]) self.assertTrue(False) except Exception: self.assertEqual(mock_exit.call_count, 1)
def test_rejects_missing_configuration_path(self, mock_exit, mock_exists, mock_stderr): # pylint: disable=unused-argument try: c, f, v, d, cfp, lcm, _ = parse_args( ["-configuration-path:/foo/bar.conf"]) # pylint: disable=unused-variable except Exception: self.assertEqual(mock_exit.call_count, 1)
def test_it_should_parse_setup_firewall_properly(self): test_firewall_meta = {"dst_ip": "1.2.3.4", "uid": "9999", "wait": "-w"} cmd, _, _, _, _, _, firewall_metadata = parse_args([ "-{0}".format(AgentCommands.SetupFirewall), "-dst_ip=1.2.3.4", "-uid=9999", "-w" ]) self.assertEqual(cmd, AgentCommands.SetupFirewall) self.assertEqual(firewall_metadata, test_firewall_meta) # Defaults to None if command is different test_firewall_meta = {"dst_ip": None, "uid": None, "wait": ""} cmd, _, _, _, _, _, firewall_metadata = parse_args( ["-{0}".format(AgentCommands.Help)]) self.assertEqual(cmd, AgentCommands.Help) self.assertEqual(test_firewall_meta, firewall_metadata)
def test_it_should_ignore_empty_arguments(self): test_firewall_meta = {"dst_ip": "1.2.3.4", "uid": "9999", "wait": ""} cmd, _, _, _, _, _, firewall_metadata = parse_args([ "-{0}".format(AgentCommands.SetupFirewall), "-dst_ip=1.2.3.4", "-uid=9999", "" ]) self.assertEqual(cmd, AgentCommands.SetupFirewall) self.assertEqual(firewall_metadata, test_firewall_meta)
def test_checks_configuration_path(self, mock_exists): conf_path = "/foo/bar-baz/something.conf" c, f, v, d, cfp = parse_args(["-configuration-path:" + conf_path]) self.assertEqual(cfp, conf_path) self.assertEqual(mock_exists.call_count, 1)
def test_accepts_configuration_path(self): conf_path = os.path.join(data_dir, "test_waagent.conf") c, f, v, d, cfp = parse_args(["-configuration-path:" + conf_path]) self.assertEqual(cfp, conf_path)
def test_configuration_path_defaults_to_none(self): c, f, v, d, cfp = parse_args([]) self.assertEqual(cfp, None)
def test_checks_configuration_path(self, mock_exists): conf_path = "/foo/bar-baz/something.conf" c, f, v, d, cfp, lcm, _ = parse_args(["-configuration-path:"+conf_path]) # pylint: disable=unused-variable self.assertEqual(cfp, conf_path) self.assertEqual(mock_exists.call_count, 1)
def test_accepts_configuration_path(self): conf_path = os.path.join(data_dir, "test_waagent.conf") c, f, v, d, cfp, lcm, _ = parse_args(["-configuration-path:" + conf_path]) # pylint: disable=unused-variable self.assertEqual(cfp, conf_path)
def test_rejects_invalid_log_collector_mode(self, mock_exit, mock_stderr): # pylint: disable=unused-argument try: c, f, v, d, cfp, lcm, _ = parse_args(["-collect-logs", "-notvalid"]) # pylint: disable=unused-variable except Exception: self.assertEqual(mock_exit.call_count, 1)
def test_configuration_path_defaults_to_none(self): c, f, v, d, cfp, lcm, _ = parse_args([]) # pylint: disable=unused-variable self.assertEqual(cfp, None)