예제 #1
0
    def list(self, _include=None, sort=None, is_descending=False, **kwargs):
        """
        Returns a list of available plugins.
        :param _include: List of fields to include in response.
        :param sort: Key for sorting the list.
        :param is_descending: True for descending order, False for ascending.
        :param kwargs: Optional filter fields. For a list of available fields
               see the REST service's models.Execution.fields
        :return: Plugins list.
        """
        params = kwargs
        if sort:
            params['_sort'] = '-' + sort if is_descending else sort

        response = self.api.get('/plugins', _include=_include, params=params)
        return ListResponse([Plugin(item) for item in response['items']],
                            response['metadata'])
예제 #2
0
    def get_config(self, name=None, scope=None):
        """Get configuration of the manager.

        If name is provided, only return that single value. If scope is
        provided, return all values for that scope.
        """
        if name and scope:
            raise ValueError('Pass either name or scope, not both')
        if name:
            response = self.api.get('/config/{0}'.format(name))
            return ConfigItem(response)

        if scope:
            response = self.api.get('/config', params={'scope': scope})
        else:
            response = self.api.get('/config')
        return ListResponse([ConfigItem(item) for item in response['items']],
                            response['metadata'])
예제 #3
0
    def list(self, _include=None, sort=None, is_descending=False, **kwargs):
        """Returns a list of currently stored log bundles.
        :param _include: List of fields to include in response.
        :param sort: Key for sorting the list.
        :param is_descending: True for descending order, False for ascending.
        :param kwargs: Optional filter fields. For a list of available fields
               see the REST service's models.LogBundle.fields
        :return: LogBundles list.
        """
        params = kwargs
        if sort:
            params['_sort'] = '-' + sort if is_descending else sort

        response = self.api.get(self.base_url.rstrip('/'),
                                params=params,
                                _include=_include)
        return ListResponse([LogBundle(item) for item in response['items']],
                            response['metadata'])
    def list(self, _include=None, sort=None, is_descending=False, **kwargs):
        """List deployment updates

        :param _include: List of fields to include in response.
        :param sort: Key for sorting the list.
        :param is_descending: True for descending order, False for ascending.
        :param kwargs: Optional filter fields. for a list of available fields
               see the REST service's models.DeploymentUpdate.fields
        """

        uri = '/deployment-updates'
        params = kwargs
        if sort:
            params['_sort'] = '-' + sort if is_descending else sort

        response = self.api.get(uri, params=params, _include=_include)
        items = [DeploymentUpdate(item) for item in response['items']]
        return ListResponse(items, response['metadata'])
예제 #5
0
    def list(self, sort=None, is_descending=False, **kwargs):
        """
        Returns a list of currently stored secrets.

        :param sort: Key for sorting the list.
        :param is_descending: True for descending order, False for ascending.
        :param kwargs: Optional filter fields. For a list of available fields
               see the REST service's models.Secret.fields
        :return: Secrets list.
        """

        params = kwargs
        if sort:
            params['_sort'] = '-' + sort if is_descending else sort

        response = self.api.get('/secrets', params=params)
        return ListResponse([Secret(item) for item in response['items']],
                            response['metadata'])
예제 #6
0
    def list(self, sort=None, is_descending=False, **kwargs):
        """Returns a list of all filters.

        :param sort: Key for sorting the list
        :param is_descending: True for descending order, False for ascending
        :param kwargs: Optional parameters. Can be: `_sort`, `_include`,
               `_size`, `_offset`, `_all_tenants'`, or `_search`
        :return: The filters list
        """
        params = kwargs
        if '_include' in params:
            params['_include'] = ','.join(params['_include'])
        if sort:
            params['_sort'] = '-' + sort if is_descending else sort

        response = self.api.get(self.uri, params=params)
        return ListResponse([Filter(item) for item in response['items']],
                            response['metadata'])
예제 #7
0
    def list(self, _include=None, sort=None, is_descending=False, **kwargs):
        """List the agents installed from the manager.
        :param _include: List of fields to include in response.
        :param sort: Key for sorting the list.
        :param is_descending: True for descending order, False for ascending.
        :param kwargs: Optional filter fields. For a list of available fields
               see the REST service's models.Agent.fields
        :return: A ListResponse containing the agents' details
        """
        if sort:
            kwargs['_sort'] = '-' + sort if is_descending else sort

        kwargs.setdefault('state', [AgentState.STARTED])
        response = self.api.get('/{self._uri_prefix}'.format(self=self),
                                _include=_include,
                                params=kwargs)
        return ListResponse(
            [self._wrapper_cls(item) for item in response['items']],
            response['metadata'])
예제 #8
0
    def list(
        self,
        graph_id=None,
        _offset=None,
        _size=None,
        execution_id=None,
        state=None,
        skip_internal=False,
    ):
        """List operations for the given graph or execution.

        :param graph_id: list operations for this graph
        :param execution_id: list operations for all graphs of this execution.
            Mutually exclusive with graph_id.
        :param state: only list operations in this state
        :param skip_internal: skip "uninteresting" internal operations; this
            will skip all local tasks and NOP tasks, and only return remote
            and subgraph tasks
        :param _offset: pagination offset
        :param _size: pagination size
        """
        params = {}
        if graph_id and execution_id:
            raise RuntimeError(
                'Pass either graph_id or execution_id, not both')
        if graph_id:
            params['graph_id'] = graph_id
        if execution_id:
            params['execution_id'] = execution_id
        if state:
            params['state'] = state
        if skip_internal:
            params['skip_internal'] = True
        if _offset is not None:
            params['_offset'] = _offset
        if _size is not None:
            params['_size'] = _size
        response = self.api.get('/{self._uri_prefix}'.format(self=self),
                                params=params)
        return ListResponse(
            [self._wrapper_cls(item) for item in response['items']],
            response['metadata'])
예제 #9
0
    def list(self, _include=None, sort=None, is_descending=False, **kwargs):
        """
        Returns a list of currently stored user groups.

        :param _include: List of fields to include in response.
        :param sort: Key for sorting the list.
        :param is_descending: True for descending order, False for ascending.
        :param kwargs: Optional filter fields. For a list of available fields
               see the REST service's models.BlueprintState.fields
        :return: Blueprints list.
        """
        params = kwargs
        if sort:
            params['_sort'] = '-' + sort if is_descending else sort

        response = self.api.get('/user-groups',
                                _include=_include,
                                params=params)
        return ListResponse([Group(item) for item in response['items']],
                            response['metadata'])
예제 #10
0
    def list(self,
             deployment_id=None,
             node_name=None,
             node_id=None,
             _include=None,
             **kwargs):
        """
        Returns a list of node instances which belong to the deployment
        identified by the provided deployment id.

        :param deployment_id: Optional deployment id to list node instances
                              for.
        :param node_name: Optional node name to only fetch node instances with
                          this name. The node_name positional argument will be
                          deprecated as of the next rest-client version.
                          Use node_id instead.
        :param node_id: Equivalent to node_name.
        :param _include: List of fields to include in response.
        :param kwargs: Optional filter fields. for a list of available fields
               see the REST service's models.DeploymentNodeInstance.fields
        :return: Node instances.
        :rtype: list
        """
        params = {}
        if node_name:
            warnings.warn(
                "'node_name' filtering capability is deprecated, use"
                " 'node_id' instead", DeprecationWarning)
            params['node_id'] = node_name
        elif node_id:
            params['node_id'] = node_id
        if deployment_id:
            params['deployment_id'] = deployment_id

        params.update(kwargs)
        response = self.api.get('/node-instances',
                                params=params,
                                _include=_include)

        return ListResponse([NodeInstance(item) for item in response['items']],
                            response['metadata'])
예제 #11
0
    def list(self, _include=None, sort=None, is_descending=False, **kwargs):
        """
        Returns a list of currently stored sites.

        :param _include: List of fields to include in response.
        :param sort: Key for sorting the list.
        :param is_descending: True for descending order, False for ascending.
        :param kwargs: Optional filter fields. For a list of available fields
               see the REST service's models.Site.fields
        :return: Sites list.
        """

        if sort:
            kwargs['_sort'] = '-' + sort if is_descending else sort

        response = self.api.get('/{self._uri_prefix}'.format(self=self),
                                _include=_include,
                                params=kwargs)
        return ListResponse(
            [self._wrapper_cls(item) for item in response['items']],
            response['metadata'])
예제 #12
0
    def list(self, _include=None, **kwargs):
        """Returns a list of executions.

        :param deployment_id: Optional deployment id to get executions for.
        :param include_system_workflows: Include executions of system
               workflows
        :param _include: List of fields to include in response.
        :param sort: Key for sorting the list.
        :param is_descending: True for descending order, False for ascending.
        :param kwargs: Optional filter fields. For a list of available fields
               see the REST service's models.Execution.fields
        :return: Executions list.
        """
        params = self._create_filters(**kwargs)

        response = self.api.get('/{self._uri_prefix}'.format(self=self),
                                params=params,
                                _include=_include)
        return ListResponse(
            [self._wrapper_cls(item) for item in response['items']],
            response['metadata'])
예제 #13
0
    def list(self, _include=None, sort=None, is_descending=False,
             filter_id=None, filter_rules=None, constraints=None, **kwargs):
        """
        Returns a list of all deployments.

        :param _include: List of fields to include in response.
        :param sort: Key for sorting the list.
        :param is_descending: True for descending order, False for ascending.
        :param filter_id: A filter ID to filter the deployments list by
        :param filter_rules: A list of filter rules to filter the
               deployments list by
        :param constraints: A list of DSL constraints for deployment_id data
               type.  The purpose is similar to the `filter_rules`, but syntax
               differs.
        :param kwargs: Optional filter fields. for a list of available fields
               see the REST service's models.Deployment.fields
        :return: Deployments list.
        """
        if constraints and (filter_id or filter_rules):
            raise ValueError('provide either DSL constraints or '
                             'filter_id/filter_rules, not both')
        params = kwargs
        if sort:
            params['_sort'] = '-' + sort if is_descending else sort
        if _include:
            params['_include'] = ','.join(_include)
        if filter_id:
            params['_filter_id'] = filter_id

        if filter_rules:
            response = self.api.post('/searches/deployments', params=params,
                                     data={'filter_rules': filter_rules})
        elif constraints:
            response = self.api.post('/searches/deployments', params=params,
                                     data={'constraints': constraints})
        else:
            response = self.api.get('/deployments', params=params)

        return ListResponse([Deployment(item) for item in response['items']],
                            response['metadata'])
예제 #14
0
    def list(self, _include=None, constraints=None, **kwargs):
        """
        Returns a list of node instances which belong to the deployment
        identified by the provided deployment id.

        :param deployment_id: Optional deployment id to list node instances
                              for.
        :param node_name: Optional node name to only fetch node instances with
                          this name. The node_name positional argument will be
                          deprecated as of the next rest-client version.
                          Use node_id instead.
        :param node_id: Equivalent to node_name.
        :param _include: List of fields to include in response.
        :param sort: Key for sorting the list.
        :param is_descending: True for descending order, False for ascending.
        :param constraints: A list of DSL constraints for node_instance data
                            type to filter the node_instances by.
        :param kwargs: Optional filter fields. for a list of available fields
               see the REST service's models.DeploymentNodeInstance.fields
        :return: Node instances.
        :rtype: list
        """

        params = self._create_filters(**kwargs)
        if constraints is None:
            response = self.api.get('/{self._uri_prefix}'.format(self=self),
                                    params=params,
                                    _include=_include)
        else:
            if _include:
                params['_include'] = ','.join(_include)
            response = self.api.post(
                '/searches/{self._uri_prefix}'.format(self=self),
                params=params,
                data={'constraints': constraints})

        return ListResponse(
            [self._wrapper_cls(item) for item in response['items']],
            response['metadata'])
예제 #15
0
    def list(self, deployment_id, constraints=None, _include=None, **kwargs):
        """
        Returns a list of deployment's scaling groups matching constraints.

        :param deployment_id: An identifier of a deployment which scaling
               groups are going to be searched.
        :param constraints: A list of DSL constraints for scaling_group
               data type to filter the scaling groups by.
        :param _include: List of fields to include in response.
        :param kwargs: Optional filter fields. for a list of available fields
               see the REST service's models.Deployment.fields
        :return: DeploymentScalingGroup list.
        """
        params = copy(kwargs) or {}
        params['deployment_id'] = deployment_id
        if _include:
            params['_include'] = ','.join(_include)

        response = self.api.post('/searches/scaling-groups', params=params,
                                 data={'constraints': constraints or {}})
        return ListResponse(
            items=[DeploymentScalingGroup(item) for item in response['items']],
            metadata=response['metadata']
        )
예제 #16
0
    def list(self,
             deployment_id=None,
             include_system_workflows=False,
             _include=None,
             **kwargs):
        """Returns a list of executions.

        :param deployment_id: Optional deployment id to get executions for.
        :param _include_system_workflows: Include executions of system
               workflows
        :param _include: List of fields to include in response.
        :param kwargs: Optional filter fields. For a list of available fields
               see the REST service's models.Execution.fields
        :return: Executions list.
        """
        uri = '/executions'
        params = {'_include_system_workflows': include_system_workflows}
        if deployment_id:
            params['deployment_id'] = deployment_id
        params.update(kwargs)

        response = self.api.get(uri, params=params, _include=_include)
        return ListResponse([Execution(item) for item in response['items']],
                            response['metadata'])
예제 #17
0
    def search(self, ids, all_tenants=False):
        """Search node instances by their IDs.

        :param ids: list of ids to search by
        :param all_tenants: search node-instances of all tenants
        :return: Node instances.
        :rtype: list
        """
        params = {}
        if all_tenants:
            params['_all_tenants'] = True
        response = self.api.post('/searches/node-instances',
                                 data={
                                     'filter_rules': [{
                                         'key': 'id',
                                         'values': ids,
                                         'operator': 'any_of',
                                         'type': 'attribute'
                                     }]
                                 },
                                 params=params)
        return ListResponse(
            [self._wrapper_cls(item) for item in response['items']],
            response['metadata'])
예제 #18
0
    def list(self, filter_id=None, filter_rules=None, **kwargs):
        """
        Returns a list of workflows.

        :param filter_id: A filter ID to filter the deployments list by
        :param filter_rules: A list of filter rules to filter the
               deployments list by
        :param kwargs: Optional filter fields. for a list of available fields
               see the REST service's models.Deployment.fields
        :return: Workflows list.
        """
        params = kwargs
        if filter_id:
            params['_filter_id'] = filter_id

        if filter_rules:
            response = self.api.post('/searches/workflows',
                                     params=params,
                                     data={'filter_rules': filter_rules})
        else:
            response = self.api.get('/workflows', params=params)

        return ListResponse([Workflow(item) for item in response['items']],
                            response['metadata'])
예제 #19
0
    def list(self, include_logs=False, message=None, from_datetime=None,
             to_datetime=None, _include=None, sort=None, **kwargs):
        """List events

        :param include_logs: Whether to also get logs.
        :param message: an expression used for wildcard search events
                        by their message text
        :param from_datetime: search for events later or equal to datetime
        :param to_datetime: search for events earlier or equal to datetime
        :param _include: return only an exclusive list of fields
        :param sort: Key for sorting the list.
        :return: dict with 'metadata' and 'items' fields
        """

        uri = '/events'
        params = self._create_query(include_logs=include_logs,
                                    message=message,
                                    from_datetime=from_datetime,
                                    to_datetime=to_datetime,
                                    sort=sort,
                                    **kwargs)

        response = self.api.get(uri, _include=_include, params=params)
        return ListResponse(response['items'], response['metadata'])
예제 #20
0
class AgentsTests(CliCommandTest):
    def setUp(self):
        super(AgentsTests, self).setUp()
        self.use_manager()

    @staticmethod
    def _agent_filters(node_ids=None, node_instance_ids=None,
                       deployment_ids=None, install_methods=None):
        return {cfy.AGENT_FILTER_NODE_IDS: node_ids,
                cfy.AGENT_FILTER_NODE_INSTANCE_IDS: node_instance_ids,
                cfy.AGENT_FILTER_DEPLOYMENT_ID: deployment_ids,
                cfy.AGENT_FILTER_INSTALL_METHODS: install_methods}

    DEFAULT_TOPOLOGY = [
        _node_instance(DEFAULT_TENANT_NAME, 't0d0node1_1', 'node1', 'd0'),
        _node_instance(DEFAULT_TENANT_NAME, 't0d0node1_2', 'node1', 'd0'),
        _node_instance(DEFAULT_TENANT_NAME, 't0d0node2_1', 'node2', 'd0'),
        _node_instance(DEFAULT_TENANT_NAME, 't0d1node1_1', 'node1', 'd1'),
        _node_instance(DEFAULT_TENANT_NAME, 't0d1node1_2', 'node1', 'd1'),
        _node_instance(DEFAULT_TENANT_NAME, 't0d1node3_1', 'node3', 'd1'),
        _node_instance('other_tenant', 't1d0node1_1', 'node1', 'd0'),
        _node_instance('other_tenant', 't1d0node1_2', 'node1', 'd0'),
        _node_instance('other_tenant', 't1d1node3_1', 'node3', 'd1'),
        _node_instance('other_tenant', 't1d2node4_1', 'node4', 'd2'),
        ]

    def mock_client(self, topology):
        def _topology_filter(predicate, **kwargs):
            tenant_name = self.client._client.headers.get(
                CLOUDIFY_TENANT_HEADER)
            if not tenant_name:
                tenant_name = DEFAULT_TENANT_NAME
            results = list()
            all_tenants = kwargs.get('_all_tenants', False)
            for node_instance in topology:
                ni_tenant_name = node_instance['tenant_name']
                if (all_tenants or ni_tenant_name == tenant_name) \
                        and predicate(node_instance):
                    results.append(node_instance)
            return results

        def list_node_instances(**kwargs):
            def _matcher(node_instance):
                ni_id = node_instance['id']
                ni_node_id = node_instance['node_id']
                ni_dep_id = node_instance['deployment_id']
                return ni_id in kwargs.get('id', [ni_id]) and \
                    ni_node_id in kwargs.get('node_id', [ni_node_id]) and \
                    ni_dep_id in kwargs.get('deployment_id', [ni_dep_id])

            return _topology_filter(_matcher, **kwargs)

        def list_deployments(**kwargs):
            tenant_name = self.client._client.headers.get(
                CLOUDIFY_TENANT_HEADER)
            if not tenant_name:
                tenant_name = DEFAULT_TENANT_NAME
            all_node_instances = _topology_filter(lambda x: True, **kwargs)
            deployments = {(x['tenant_name'], x['deployment_id'])
                           for x in all_node_instances}
            deployments = [Deployment({'id': b, 'tenant_name': a}) for a, b in
                           deployments]
            results = list()
            searched_ids = kwargs['id']
            for dep in deployments:
                if (not searched_ids) or dep.id in searched_ids:
                    results.append(dep)
            return results

        def list_nodes(**kwargs):
            node_ids = kwargs.get('id')
            all_node_instances = _topology_filter(lambda x: True, **kwargs)
            nodes = {(x['tenant_name'], x['deployment_id'], x['node_id'])
                     for x in all_node_instances}
            nodes = [Node({'id': c, 'deployment_id': b, 'tenant_name': a}) for
                     (a, b, c) in nodes]
            return list(filter(
                lambda x: (node_ids is None) or x['id'] in node_ids, nodes))

        self.client.node_instances.list = list_node_instances
        self.client.deployments.list = list_deployments
        self.client.nodes.list = list_nodes

    def assert_execution_started(self, client_mock, deployment_id,
                                 filters):
        self.assertIn(
            ((deployment_id, 'workflow', filters), {
                'allow_custom_parameters': True
            }), client_mock.call_args_list)

    # Tests for get_node_instances_map

    def test_parameters_error(self):
        self.mock_client({})
        self.assertRaises(
            CloudifyCliError,
            get_filters_map,
            self.client,
            self.logger,
            AgentsTests._agent_filters(
                node_instance_ids=['a1'],
                deployment_ids=['d1']
            ),
            [DEFAULT_TENANT_NAME])

    def test_filters_map_empty(self):
        self.mock_client({})
        results = get_filters_map(
            self.client, self.logger, AgentsTests._agent_filters(), False)
        self.assertFalse(results)

    def test_filters_map_empty_node_instances(self):
        self.mock_client({})
        self.assertRaises(
            CloudifyCliError,
            get_filters_map,
            self.client,
            self.logger,
            AgentsTests._agent_filters(node_instance_ids=['t0d0node1_1']),
            False)

    def test_filters_map_empty_deployment_ids(self):
        self.mock_client({})
        self.assertRaises(
            CloudifyCliError,
            get_filters_map,
            self.client,
            self.logger,
            AgentsTests._agent_filters(deployment_ids=['d0']),
            False)

    def test_filters_map_all(self):
        self.mock_client(AgentsTests.DEFAULT_TOPOLOGY)
        results = get_filters_map(
            self.client, self.logger, AgentsTests._agent_filters(),
            True)
        self.assertEquals({
            DEFAULT_TENANT_NAME: {
                'd0': {},
                'd1': {}
            },
            'other_tenant': {
                'd0': {},
                'd1': {},
                'd2': {}
            }
        }, results)

    def test_filters_map_node_id_single_tenant(self):
        self.mock_client(AgentsTests.DEFAULT_TOPOLOGY)
        results = get_filters_map(
            self.client, self.logger, AgentsTests._agent_filters(
                node_ids=['node1']), False)

        self.assertEquals({
            DEFAULT_TENANT_NAME: {
                'd0': {'node_ids': ['node1']},
                'd1': {'node_ids': ['node1']}
            }
        }, results)

    def test_filters_map_node_id_all_tenants(self):
        self.mock_client(AgentsTests.DEFAULT_TOPOLOGY)
        results = get_filters_map(
            self.client, self.logger, AgentsTests._agent_filters(
                node_ids=['node1']), True)

        self.assertEquals({
            DEFAULT_TENANT_NAME: {
                'd0': {
                    'node_ids': ['node1']
                },
                'd1': {
                    'node_ids': ['node1']
                }
            },
            'other_tenant': {
                'd0': {
                    'node_ids': ['node1']
                }
            }
        }, results)

    def test_filters_map_dep_id_single_tenant(self):
        self.mock_client(AgentsTests.DEFAULT_TOPOLOGY)
        results = get_filters_map(
            self.client, self.logger, AgentsTests._agent_filters(
                deployment_ids=['d0']), False)

        self.assertEquals({
            DEFAULT_TENANT_NAME: {
                'd0': {}
            }
        }, results)

    def test_filters_map_dep_id_all_tenants(self):
        self.mock_client(AgentsTests.DEFAULT_TOPOLOGY)
        results = get_filters_map(
            self.client, self.logger, AgentsTests._agent_filters(
                deployment_ids=['d0']), True)

        self.assertEquals({
            DEFAULT_TENANT_NAME: {
                'd0': {}
            },
            'other_tenant': {
                'd0': {}
            }
        }, results)

    def test_filters_map_bad_dep_id(self):
        self.mock_client(AgentsTests.DEFAULT_TOPOLOGY)
        self.assertRaises(
            CloudifyCliError,
            get_filters_map,
            self.client,
            self.logger,
            AgentsTests._agent_filters(deployment_ids=['error']),
            False)

    # Tests for get_deployments_and_run_workers

    def test_empty_node_instances_map(self):
        self.mock_client({})
        self.assertRaises(
            CloudifyCliError,
            get_deployments_and_run_workers,
            self.client,
            self._agent_filters(),
            [],
            self.logger,
            '',
            False)

    @patch.object(ExecutionsClient, 'start')
    def test_full_topology(self, exec_client_mock):
        self.mock_client(AgentsTests.DEFAULT_TOPOLOGY)
        get_deployments_and_run_workers(
            self.client, self._agent_filters(),
            True, self.logger, 'workflow', False
        )

        self.assert_execution_started(exec_client_mock, 'd1', {})
        self.assert_execution_started(exec_client_mock, 'd0', {})
        self.assert_execution_started(exec_client_mock, 'd2', {})
        self.assertEquals(len(exec_client_mock.call_args_list), 5)

    @patch.object(ExecutionsClient, 'start')
    def test_full_topology_one_nonstarted(self, exec_client_mock):
        topology = list(AgentsTests.DEFAULT_TOPOLOGY)
        topology.append(_node_instance(DEFAULT_TENANT_NAME, 't0d1node4_1',
                                       'node4', 'd1', 'creating'))
        self.mock_client(topology)
        get_deployments_and_run_workers(
            self.client, self._agent_filters(),
            True, self.logger, 'workflow', False
        )
        self.assertEquals(len(exec_client_mock.call_args_list), 4)

    @patch.object(ExecutionsClient, 'start')
    def test_node_instances_map_none(self, exec_client_mock):
        self.mock_client(AgentsTests.DEFAULT_TOPOLOGY)
        get_deployments_and_run_workers(
            self.client, self._agent_filters(install_methods=['provided']),
            True, self.logger, 'workflow', False
        )
        self.assertEquals(exec_client_mock.call_count, 5)
        for call in exec_client_mock.call_args_list:
            self.assertTrue(call[0][2]['install_methods'] == ['provided'])

    @patch.object(ExecutionsClient, 'get',
                  return_value=Execution({'status': 'terminated'}))
    @patch.object(EventsClient, 'list',
                  return_value=ListResponse(
                      [],
                      Metadata({'pagination': {
                          'total': 0,
                          'offset': 0,
                          'size': 10}})))
    def test_execution_tracking(self, events_list_mock, exec_get_mock):
        self.mock_client(AgentsTests.DEFAULT_TOPOLOGY)

        def _mock_execution_start(*args, **kwargs):
            tenant_name = args[0].api.headers.get(CLOUDIFY_TENANT_HEADER)
            deployment_id = args[1]
            return Execution({'id': str(uuid.uuid4()),
                              'deployment_id': deployment_id,
                              'tenant_name': tenant_name})

        def _wait_side_effect(*args, **kwargs):
            client_tenant = args[0]._client.headers[CLOUDIFY_TENANT_HEADER]
            execution = args[1]
            self.assertEquals(client_tenant, execution['tenant_name'])
            return DEFAULT

        with patch('cloudify_cli.commands.agents.wait_for_execution',
                   return_value=PropertyMock(error=False),
                   side_effect=_wait_side_effect):
            with patch.object(ExecutionsClient, 'start',
                              _mock_execution_start):
                get_deployments_and_run_workers(
                    self.client, self._agent_filters(), True, self.logger,
                    'workflow', True)
예제 #21
0
 def list(self, **kwargs):
     response = self.api.get('/execution-groups', params=kwargs)
     return ListResponse(
         [ExecutionGroup(item) for item in response['items']],
         response['metadata'])
예제 #22
0
 def get_db_nodes(self):
     response = self.api.get('/db-nodes')
     return ListResponse(
         [DBNodeItem(item) for item in response['items']],
         response['metadata']
     )
예제 #23
0
 def list_keys(self):
     """
     Returns all defined label keys, from all deployments.
     """
     response = self.api.get('/labels/deployments')
     return ListResponse(response['items'], response['metadata'])
예제 #24
0
 def get_reserved_labels_keys(self):
     """Returns the reserved labels keys (`csys-` prefixed)."""
     response = self.api.get('/labels/{0}'.format(self.resource_name),
                             params={'_reserved': True})
     return ListResponse(response['items'], response['metadata'])
예제 #25
0
 def _wrap_list(self, response):
     return ListResponse(
         [self._wrapper_cls(item) for item in response['items']],
         response['metadata']
     )
예제 #26
0
 def list_keys(self):
     """
     Returns all defined label keys, from all elements of the resource.
     """
     response = self.api.get('/labels/{0}'.format(self.resource_name))
     return ListResponse(response['items'], response['metadata'])
예제 #27
0
 def base_list_return(self, *args, **_):
     del args
     return ListResponse([self.list_mock], metadata={})
예제 #28
0
 def get_brokers(self):
     response = self.api.get('/brokers', )
     return ListResponse(
         [RabbitMQBrokerItem(item) for item in response['items']],
         response['metadata'])