Пример #1
0
    def test_run_in_model_not_awaitable(self):
        self.patch_object(model, 'Model')

        def _test_func(arg):
            return arg * 3

        self.Model.return_value = self.Model_mock
        func = functools.partial(_test_func, 'hello')
        out = loop.run(model.run_in_model('mymodel', func, awaitable=False))
        self.assertEqual(out, 'hellohellohello')
Пример #2
0
async def async_wait_for_service_status(unit_name,
                                        services,
                                        target_status,
                                        model_name=None,
                                        timeout=2700):
    """Wait for all services on the unit to be in the desired state.

    Note: This function emulates the
    `zaza.model.async_block_until_service_status` function, but it's using
    `systemctl is-active` command instead of `pidof/pgrep` of the original
    function.

    :param unit_name: Name of unit to run action on
    :type unit_name: str
    :param services: List of services to check
    :type services: List[str]
    :param target_status: State services must be in (stopped or running)
    :type target_status: str
    :param model_name: Name of model to query.
    :type model_name: str
    :param timeout: Time to wait for status to be achieved
    :type timeout: int
    """
    async def _check_service():
        services_ok = True
        for service in services:
            command = r"systemctl is-active '{}'".format(service)
            out = await zaza_model.async_run_on_unit(unit_name,
                                                     command,
                                                     model_name=model_name,
                                                     timeout=timeout)
            response = out['Stdout'].strip()

            if target_status == "running" and response == 'active':
                continue
            elif target_status == "stopped" and response == 'inactive':
                continue
            else:
                services_ok = False
                break

        return services_ok

    accepted_states = ('stopped', 'running')
    if target_status not in accepted_states:
        raise RuntimeError('Invalid target state "{}". Accepted states: '
                           '{}'.format(target_status, accepted_states))

    async with zaza_model.run_in_model(model_name):
        await zaza_model.async_block_until(_check_service, timeout=timeout)
Пример #3
0
    def test_run_in_model_add_model_arg(self):
        self.patch_object(model, 'Model')

        def _test_func(arg, model):
            return model

        self.Model.return_value = self.Model_mock
        func = functools.partial(_test_func, 'hello')
        out = loop.run(
            model.run_in_model('mymodel',
                               func,
                               add_model_arg=True,
                               awaitable=False))
        self.assertEqual(out, self.Model_mock)
Пример #4
0
 async def _wrapper():
     async with model.run_in_model('modelname') as mymodel:
         return mymodel