Exemple #1
0
    def test_orch_preparesite(self, input_files):
        objects.register_all()

        input_file = input_files.join("fullsite.yaml")

        design_state = statemgmt.DesignState()
        design_data = objects.SiteDesign()
        design_id = design_data.assign_id()
        design_state.post_design(design_data)

        ingester = Ingester()
        ingester.enable_plugins([drydock_provisioner.ingester.plugins.yaml.YamlIngester])
        ingester.ingest_data(plugin_name='yaml', design_state=design_state,
                             filenames=[str(input_file)], design_id=design_id)

        design_data = design_state.get_design(design_id)

        orchestrator = orch.Orchestrator(state_manager=design_state,
                                    enabled_drivers={'node': 'drydock_provisioner.drivers.node.maasdriver.driver.MaasNodeDriver'})

        orch_task = orchestrator.create_task(task.OrchestratorTask,
                                             site='sitename',
                                             design_id=design_id,
                                             action=hd_fields.OrchestratorAction.PrepareSite)

        orchestrator.execute_task(orch_task.get_id())

        orch_task = design_state.get_task(orch_task.get_id())

        assert orch_task.result == hd_fields.ActionResult.Success
Exemple #2
0
    def test_client_verify(self):
        design_state = statemgmt.DesignState()
        orchestrator = orch.Orchestrator(state_manager=design_state,
                                    enabled_drivers={'node': 'drydock_provisioner.drivers.node.maasdriver.driver.MaasNodeDriver'})

        orch_task = orchestrator.create_task(task.OrchestratorTask,
                                             site='sitename',
                                             design_id=None,
                                             action=hd_fields.OrchestratorAction.VerifySite)

        orchestrator.execute_task(orch_task.get_id())

        orch_task = design_state.get_task(orch_task.get_id())

        assert orch_task.result == hd_fields.ActionResult.Success
Exemple #3
0
    def loaded_design(self, input_files):
        objects.register_all()

        input_file = input_files.join("oob.yaml")

        design_state = statemgmt.DesignState()
        design_data = objects.SiteDesign(id=self.design_id)

        design_state.post_design(design_data)

        ingester = Ingester()
        ingester.enable_plugins([yaml_ingester.YamlIngester])
        ingester.ingest_data(plugin_name='yaml', design_state=design_state,
                             design_id=self.design_id, filenames=[str(input_file)])

        return design_state
    def test_task_complete(self):
        state_mgr = statemgmt.DesignState()
        orchestrator = orch.Orchestrator(state_manager=state_mgr)
        orch_task = orchestrator.create_task(
            task.OrchestratorTask,
            site='default',
            action=hd_fields.OrchestratorAction.Noop)

        orchestrator.execute_task(orch_task.get_id())

        orch_task = state_mgr.get_task(orch_task.get_id())

        assert orch_task.get_status() == hd_fields.TaskStatus.Complete

        for t_id in orch_task.subtasks:
            t = state_mgr.get_task(t_id)
            assert t.get_status() == hd_fields.TaskStatus.Complete
Exemple #5
0
    def test_sitedesign_post(self):
        objects.register_all()

        state_manager = statemgmt.DesignState()
        design_data = objects.SiteDesign()
        design_id = design_data.assign_id()

        initial_site = objects.Site()
        initial_site.name = 'testsite'

        net_a = objects.Network()
        net_a.name = 'net_a'
        net_a.region = 'testsite'
        net_a.cidr = '172.16.0.0/24'

        design_data.set_site(initial_site)
        design_data.add_network(net_a)

        state_manager.post_design(design_data)

        my_design = state_manager.get_design(design_id)

        assert design_data.obj_to_primitive() == my_design.obj_to_primitive()
Exemple #6
0
def start_drydock():
    objects.register_all()

    # Setup root logger
    logger = logging.getLogger('drydock')

    logger.setLevel(config.DrydockConfig.global_config.get('log_level'))
    ch = logging.StreamHandler()
    formatter = logging.Formatter(
        '%(asctime)s - %(levelname)s - %(filename)s:%(funcName)s - %(message)s'
    )
    ch.setFormatter(formatter)
    logger.addHandler(ch)

    # Specalized format for API logging
    logger = logging.getLogger('drydock.control')
    logger.propagate = False
    formatter = logging.Formatter(
        '%(asctime)s - %(levelname)s - %(user)s - %(req_id)s - %(external_ctx)s - %(message)s'
    )

    ch = logging.StreamHandler()
    ch.setFormatter(formatter)
    logger.addHandler(ch)

    state = statemgmt.DesignState()

    orchestrator = orch.Orchestrator(
        config.DrydockConfig.orchestrator_config.get('drivers', {}),
        state_manager=state)
    input_ingester = ingester.Ingester()
    input_ingester.enable_plugins(
        config.DrydockConfig.ingester_config.get('plugins', []))

    return api.start_api(state_manager=state,
                         ingester=input_ingester,
                         orchestrator=orchestrator)
    def test_task_termination(self):
        state_mgr = statemgmt.DesignState()
        orchestrator = orch.Orchestrator(state_manager=state_mgr)
        orch_task = orchestrator.create_task(
            task.OrchestratorTask,
            site='default',
            action=hd_fields.OrchestratorAction.Noop)

        orch_thread = threading.Thread(target=orchestrator.execute_task,
                                       args=(orch_task.get_id(), ))
        orch_thread.start()

        time.sleep(1)
        orchestrator.terminate_task(orch_task.get_id())

        while orch_thread.is_alive():
            time.sleep(1)

        orch_task = state_mgr.get_task(orch_task.get_id())
        assert orch_task.get_status() == hd_fields.TaskStatus.Terminated

        for t_id in orch_task.subtasks:
            t = state_mgr.get_task(t_id)
            assert t.get_status() == hd_fields.TaskStatus.Terminated
Exemple #8
0
def start_drydock():
    objects.register_all()

    # Setup configuration parsing
    cli_options = [
        cfg.BoolOpt('debug',
                    short='d',
                    default=False,
                    help='Enable debug logging'),
    ]

    cfg.CONF.register_cli_opts(cli_options)
    config.config_mgr.register_options()
    cfg.CONF(sys.argv[1:])

    if cfg.CONF.debug:
        cfg.CONF.set_override(name='log_level',
                              override='DEBUG',
                              group='logging')

    # Setup root logger
    logger = logging.getLogger(cfg.CONF.logging.global_logger_name)

    logger.setLevel(cfg.CONF.logging.log_level)
    ch = logging.StreamHandler()
    formatter = logging.Formatter(
        '%(asctime)s - %(levelname)s - %(filename)s:%(funcName)s - %(message)s'
    )
    ch.setFormatter(formatter)
    logger.addHandler(ch)

    # Specalized format for API logging
    logger = logging.getLogger(cfg.CONF.logging.control_logger_name)
    logger.propagate = False
    formatter = logging.Formatter(
        '%(asctime)s - %(levelname)s - %(user)s - %(req_id)s - %(external_ctx)s - %(message)s'
    )

    ch = logging.StreamHandler()
    ch.setFormatter(formatter)
    logger.addHandler(ch)

    state = statemgmt.DesignState()

    orchestrator = orch.Orchestrator(cfg.CONF.plugins, state_manager=state)
    input_ingester = ingester.Ingester()
    input_ingester.enable_plugins(cfg.CONF.plugins.ingester)

    # Check if we have an API key in the environment
    # Hack around until we move MaaS configs to the YAML schema
    if 'MAAS_API_KEY' in os.environ:
        cfg.CONF.set_override(name='maas_api_key',
                              override=os.environ['MAAS_API_KEY'],
                              group='maasdriver')

    # Setup the RBAC policy enforcer
    policy.policy_engine = policy.DrydockPolicy()
    policy.policy_engine.register_policy()

    # Ensure that the policy_engine is initialized before starting the API
    wsgi_callable = api.start_api(state_manager=state,
                                  ingester=input_ingester,
                                  orchestrator=orchestrator)

    # Now that loggers are configured, log the effective config
    cfg.CONF.log_opt_values(
        logging.getLogger(cfg.CONF.logging.global_logger_name), logging.DEBUG)

    return wsgi_callable