예제 #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)? ")
예제 #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"])
예제 #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)
예제 #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)
예제 #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")
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #13
0
 def test_action_manager_called_validator_function(self):
     manager = ActionManager(config_path="blaap")
     manager.execute("list")
     self.validator.validate.assert_called_once()
예제 #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")
예제 #15
0
 def test_action_manager_calls_validate_config(self):
     manager = ActionManager(config_path="blaap")
     manager.execute("list")
     self.validate.called_once_with()
예제 #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)
예제 #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)
예제 #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)
예제 #19
0
 def test_action_raises_not_implemented_error_if_unsupported_action(self):
     manager = ActionManager()
     with self.assertRaises(NotImplementedError):
         manager.execute("not_working")
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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()
예제 #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)