Exemplo n.º 1
0
 def test_action_manager_calls_request_confirmation_with_destroy_action_and_base_image(
         self):
     manager = ActionManager(config_path="blaap", base_image=True)
     manager.execute("destroy")
     self.request_confirmation.assert_called_once_with(
         prompt=
         "Are you sure you want to delete the VNet base images (y/n)? ")
Exemplo n.º 2
0
 def test_action_manager_calls_create_machines_with_create_action_and_machines_and_nohosts(
         self):
     manager = ActionManager(config_path="blaap", no_hosts=True)
     manager.machines = ["machine"]
     manager.execute("create")
     self.create_machines.assert_called_once_with(
         self.validator.updated_config, machines=["machine"])
Exemplo n.º 3
0
 def test_action_manager_calls_destroy_lxc_image_with_destroy_action_and_base_image(
         self):
     manager = ActionManager(config_path="blaap", base_image=True)
     manager.execute("destroy")
     self.destroy_lxc_image.assert_called_once_with(
         settings.LXC_BASE_IMAGE_ALIAS, by_alias=True)
     self.assertFalse(self.destroy_machines.called)
Exemplo n.º 4
0
 def test_action_manager_calls_bring_up_vnet_interfaces_with_start_action(
         self):
     manager = ActionManager(config_path="blaap")
     manager.execute("start")
     self.bring_up_vnet_interfaces.assert_called_once_with(
         self.validator.updated_config, sniffer=False)
     self.assertFalse(self.bring_down_vnet_interfaces.called)
Exemplo n.º 5
0
 def test_action_manager_calls_change_machine_status_with_stop_action_and_machines(
         self):
     manager = ActionManager(config_path="blaap")
     manager.machines = ["machine"]
     manager.execute("stop")
     self.change_machine_status.assert_called_once_with(
         self.validator.updated_config, machines=["machine"], status="stop")
Exemplo n.º 6
0
 def test_action_manager_returns_usage_exit_code_if_validator_unsuccessful(
         self):
     self.validator.config_validation_successful = False
     manager = ActionManager(config_path="blaap")
     ret = manager.execute("show")
     self.assertEqual(ret, EX_USAGE)
     self.assertFalse(self.show_status.called)
Exemplo n.º 7
0
 def test_action_manager_calls_show_vnet_veth_interface_status_with_show_action(
         self):
     self.validator.updated_config["veths"] = "jajaja"
     manager = ActionManager(config_path="blaap")
     manager.execute("show")
     self.show_status_interfaces_veth.assert_called_once_with(
         self.validator.updated_config)
Exemplo n.º 8
0
 def test_action_manager_calls_get_yaml_file_from_disk_path_with_list_action(
         self):
     self.isfile.return_value = False
     manager = ActionManager(config_path="blaap")
     manager.execute("list")
     self.get_yaml_file_from_disk_path.assert_called_once_with(
         "blaap", excludes_files=settings.CONFIG_DEFAULTS_LOCATION)
Exemplo n.º 9
0
 def test_action_manager_calls_destroy_machines_with_destroy_action_and_machines(
         self):
     manager = ActionManager(config_path="blaap")
     manager.machines = ["machine"]
     manager.execute("destroy")
     self.destroy_machines.assert_called_once_with(
         self.validator.updated_config, machines=["machine"])
     self.assertFalse(self.destroy_lxc_image.called)
Exemplo n.º 10
0
 def test_action_manager_does_nothing_when_not_file_and_not_dir_with_list_action(
         self):
     self.isfile.return_value = False
     self.isdir.return_value = False
     manager = ActionManager(config_path="blaap")
     manager.execute("list")
     self.assertFalse(self.get_yaml_file_from_disk_path.called)
     self.assertFalse(self.show_status.called)
Exemplo n.º 11
0
 def test_action_manager_calls_show_status_with_return_values_of_get_yaml_files(
         self):
     self.get_yaml_file_from_disk_path.return_value = [
         "file1", "file2", "file3"
     ]
     self.isfile.return_value = False
     manager = ActionManager(config_path="blaap")
     manager.execute("list")
     self.assertEqual(3, self.show_status.call_count)
Exemplo n.º 12
0
def main(args=None):
    """
    Program entry point
    :param list args: The pre-cooked arguments to pass to the ArgParser
    :return int: exit_code
    """
    args = parse_args(args)
    # Set the VNET_FORCE variable, if --yes is given this will answer yes to all questions
    environ[settings.VNET_FORCE_ENV_VAR] = "true" if args.yes else "false"
    # Setup logging
    setup_console_logging(verbosity=DEBUG if args.verbose else INFO)
    # Most VNet operation require root. So, do a root check
    if not check_for_root_user():
        logger.critical("This program should only be run as root")
        return EX_NOPERM
    # Let the action manager handle the rest
    manager = ActionManager(config_path=args.config,
                            sniffer=args.sniffer,
                            base_image=args.base_image,
                            no_hosts=args.no_hosts)
    if args.machines:
        manager.machines = args.machines
    return manager.execute(args.action)
Exemplo n.º 13
0
 def test_action_manager_called_validator_function(self):
     manager = ActionManager(config_path="blaap")
     manager.execute("list")
     self.validator.validate.assert_called_once()
Exemplo n.º 14
0
 def test_action_manager_calls_get_config(self):
     manager = ActionManager(config_path="blaap")
     manager.execute("list")
     self.get_config.assert_called_once_with("blaap")
Exemplo n.º 15
0
 def test_action_manager_calls_validate_config(self):
     manager = ActionManager(config_path="blaap")
     manager.execute("list")
     self.validate.called_once_with()
Exemplo n.º 16
0
 def test_action_manager_calls_show_version_with_version_action(self):
     manager = ActionManager()
     ret = manager.execute("version")
     self.show_version.assert_called_once_with()
     self.assertEqual(ret, EX_OK)
Exemplo n.º 17
0
 def test_action_manager_calls_display_help_for_action_when_action_has_been_called_with_help_as_second_parameter(
         self):
     manager = ActionManager(config_path="help")
     ret = manager.execute("start")
     self.display_help_for_action.assert_called_once_with("start")
     self.assertEqual(ret, EX_OK)
Exemplo n.º 18
0
 def test_action_manager_calls_enable_type_specific_machine_configuration_and_nohosts(
         self):
     manager = ActionManager(config_path="blaap", no_hosts=True)
     manager.execute("create")
     self.enable_type_specific_machine_configuration.assert_called_once_with(
         self.validator.updated_config)
Exemplo n.º 19
0
 def test_action_raises_not_implemented_error_if_unsupported_action(self):
     manager = ActionManager()
     with self.assertRaises(NotImplementedError):
         manager.execute("not_working")
Exemplo n.º 20
0
 def test_action_manager_calls_generate_vnet_hosts_file_with_create_action(
         self):
     manager = ActionManager(config_path="blaap")
     manager.execute("create")
     self.generate_vnet_hosts_file.assert_called_once_with(
         self.validator.updated_config)
Exemplo n.º 21
0
 def test_action_manager_does_not_call_bring_down_vnet_interfaces_with_stop_action_and_machines(
         self):
     manager = ActionManager(config_path="blaap")
     manager.machines = ["machine"]
     manager.execute("stop")
     self.assertFalse(self.bring_down_vnet_interfaces.called)
Exemplo n.º 22
0
 def test_action_manager_calls_delete_vnet_interfaces_with_destroy_action(
         self):
     manager = ActionManager(config_path="blaap")
     manager.execute("destroy")
     self.delete_vnet_interfaces.assert_called_once_with(
         self.validator.updated_config)
Exemplo n.º 23
0
 def test_action_manager_does_not_call_delete_vnet_interfaces_with_destroy_action_and_machines(
         self):
     manager = ActionManager(config_path="blaap")
     manager.machines = ["machine"]
     manager.execute("destroy")
     self.assertFalse(self.delete_vnet_interfaces.called)
Exemplo n.º 24
0
 def test_action_manager_calls_ensure_vnet_lxc_environment_with_create_action_and_nohosts(
         self):
     manager = ActionManager(config_path="blaap", no_hosts=True)
     manager.execute("create")
     self.ensure_vnet_lxc_environment.assert_called_once_with(
         self.validator.updated_config)
Exemplo n.º 25
0
 def test_action_manager_calls_put_files_on_machine_with_create_action_and_nohosts(
         self):
     manager = ActionManager(config_path="blaap", no_hosts=True)
     manager.execute("create")
     self.put_files_on_machine.assert_called_once_with(
         self.validator.updated_config)
Exemplo n.º 26
0
 def test_action_manager_calls_destroy_machines_with_destroy_action(self):
     manager = ActionManager(config_path="blaap")
     manager.execute("destroy")
     self.destroy_machines.assert_called_once_with(
         self.validator.updated_config, machines=None)
Exemplo n.º 27
0
 def test_action_manager_returns_ex_ok_after_action_has_been_completed(
         self):
     manager = ActionManager(config_path="blaap")
     ret = manager.execute("list")
     self.assertEqual(ret, EX_OK)
Exemplo n.º 28
0
 def test_action_manager_has_machine_property(self):
     manager = ActionManager()
     manager.machines = ["1", "2", "3"]
     self.assertEqual(manager.machines, ["1", "2", "3"])
     self.assertIsInstance(ActionManager.machines, property)
Exemplo n.º 29
0
 def test_action_manager_calls_cleanup_vnet_lxc_environment_with_clean_action(
         self):
     manager = ActionManager()
     manager.execute("clean")
     self.cleanup_vnet_lxc_environment.assert_called_once_with()
Exemplo n.º 30
0
 def test_action_manager_calls_generate_vnet_hosts_file_with_create_action_and_nohosts(
         self):
     manager = ActionManager(config_path="blaap", no_hosts=True)
     manager.execute("create")
     self.assertFalse(self.generate_vnet_hosts_file.called)