예제 #1
0
    def test_do_strategy_state(self):
        strategy1 = resource.Strategy(mock.Mock(), STRATEGY_1)
        strategy_req = [{
            'type': 'Datasource',
            'mandatory': True,
            'comment': '',
            'state': 'gnocchi: True'
        }, {
            'type':
            'Metrics',
            'mandatory':
            False,
            'comment':
            '',
            'state':
            jsonutils.dumps([{
                'compute.node.cpu.percent': 'available'
            }, {
                'cpu_util': 'available'
            }, {
                'memory.resident': 'available'
            }, {
                'hardware.memory.used': 'not available'
            }])
        }, {
            'type':
            'CDM',
            'mandatory':
            True,
            'comment':
            '',
            'state':
            jsonutils.dumps([{
                'compute_model': 'available'
            }, {
                'storage_model': 'not available'
            }])
        }, {
            'type': 'Name',
            'mandatory': '',
            'comment': '',
            'state': strategy1.name
        }]
        requirements = [
            resource.Strategy(mock.Mock(), req) for req in strategy_req
        ]
        self.m_strategy_mgr.state.return_value = requirements

        exit_code, results = self.run_cmd('strategy state basic')

        self.assertEqual(0, exit_code)
        self.assertEqual([
            self.resource_as_dict(req, self.STATE_FIELDS,
                                  self.STATE_FIELD_LABELS)
            for req in requirements
        ], results)
예제 #2
0
    def test_do_strategy_list_detail(self):
        strategy1 = resource.Strategy(mock.Mock(), STRATEGY_1)
        strategy2 = resource.Strategy(mock.Mock(), STRATEGY_2)
        self.m_strategy_mgr.list.return_value = [strategy1, strategy2]

        exit_code, results = self.run_cmd('strategy list --detail')

        self.assertEqual(0, exit_code)
        self.assertEqual([
            self.resource_as_dict(strategy1, self.FIELDS, self.FIELD_LABELS),
            self.resource_as_dict(strategy2, self.FIELDS, self.FIELD_LABELS)
        ], results)

        self.m_strategy_mgr.list.assert_called_once_with(detail=True)
예제 #3
0
    def test_do_audit_template_list_filter_by_goal_name(self):
        goal1 = resource.Goal(mock.Mock(), GOAL_1)
        strategy1 = resource.Strategy(mock.Mock(), STRATEGY_1)
        audit_template1 = resource.AuditTemplate(mock.Mock(), AUDIT_TEMPLATE_1)
        audit_template2 = resource.AuditTemplate(mock.Mock(), AUDIT_TEMPLATE_2)
        self.m_goal_mgr.get.return_value = goal1
        self.m_strategy_mgr.get.return_value = strategy1
        self.m_audit_template_mgr.list.return_value = [
            audit_template1, audit_template2
        ]

        exit_code, results = self.run_cmd(
            'audittemplate list --goal SERVER_CONSOLIDATION')

        self.assertEqual(0, exit_code)
        self.assertEqual([
            self.resource_as_dict(audit_template1, self.SHORT_LIST_FIELDS,
                                  self.SHORT_LIST_FIELD_LABELS),
            self.resource_as_dict(audit_template2, self.SHORT_LIST_FIELDS,
                                  self.SHORT_LIST_FIELD_LABELS)
        ], results)

        self.m_audit_template_mgr.list.assert_called_once_with(
            detail=False,
            goal='SERVER_CONSOLIDATION',
        )
예제 #4
0
    def test_do_strategy_show_by_uuid(self):
        strategy = resource.Strategy(mock.Mock(), STRATEGY_1)
        self.m_strategy_mgr.get.return_value = strategy

        exit_code, result = self.run_cmd(
            'strategy show f8e47706-efcf-49a4-a5c4-af604eb492f2')

        self.assertEqual(0, exit_code)
        self.assertEqual(
            self.resource_as_dict(strategy, self.FIELDS, self.FIELD_LABELS),
            result)
        self.m_strategy_mgr.get.assert_called_once_with(
            'f8e47706-efcf-49a4-a5c4-af604eb492f2')
예제 #5
0
    def test_do_strategy_list_marker(self):
        strategy2 = resource.Strategy(mock.Mock(), STRATEGY_2)
        self.m_strategy_mgr.list.return_value = [strategy2]

        exit_code, results = self.run_cmd(
            'strategy list --marker 2cf86250-d309-4b81-818e-1537f3dba6e5')

        self.assertEqual(0, exit_code)
        self.assertEqual([
            self.resource_as_dict(strategy2, self.SHORT_LIST_FIELDS,
                                  self.SHORT_LIST_FIELD_LABELS)
        ], results)

        self.m_strategy_mgr.list.assert_called_once_with(
            detail=False, marker='2cf86250-d309-4b81-818e-1537f3dba6e5')
예제 #6
0
    def test_do_strategy_list_filter_by_goal_name(self):
        strategy2 = resource.Strategy(mock.Mock(), STRATEGY_2)
        self.m_strategy_mgr.list.return_value = [strategy2]

        exit_code, results = self.run_cmd('strategy list --goal ' 'DUMMY')

        self.assertEqual(0, exit_code)
        self.assertEqual([
            self.resource_as_dict(strategy2, self.SHORT_LIST_FIELDS,
                                  self.SHORT_LIST_FIELD_LABELS)
        ], results)

        self.m_strategy_mgr.list.assert_called_once_with(
            detail=False,
            goal='DUMMY',
        )
예제 #7
0
    def test_do_strategy_list_filter_by_goal_uuid(self):
        strategy1 = resource.Strategy(mock.Mock(), STRATEGY_1)
        self.m_strategy_mgr.list.return_value = [strategy1]

        exit_code, results = self.run_cmd(
            'strategy list --goal '
            'fc087747-61be-4aad-8126-b701731ae836')

        self.assertEqual(0, exit_code)
        self.assertEqual([
            self.resource_as_dict(strategy1, self.SHORT_LIST_FIELDS,
                                  self.SHORT_LIST_FIELD_LABELS)
        ], results)

        self.m_strategy_mgr.list.assert_called_once_with(
            detail=False,
            goal='fc087747-61be-4aad-8126-b701731ae836',
        )
예제 #8
0
    def test_do_audit_template_list_filter_by_strategy_uuid(self):
        goal1 = resource.Goal(mock.Mock(), GOAL_1)
        strategy1 = resource.Strategy(mock.Mock(), STRATEGY_1)
        audit_template1 = resource.AuditTemplate(mock.Mock(), AUDIT_TEMPLATE_1)
        self.m_goal_mgr.get.return_value = goal1
        self.m_strategy_mgr.get.return_value = strategy1
        self.m_audit_template_mgr.list.return_value = [audit_template1]

        exit_code, results = self.run_cmd(
            'audittemplate list --strategy '
            '2cf86250-d309-4b81-818e-1537f3dba6e5')

        self.assertEqual(0, exit_code)
        self.assertEqual([
            self.resource_as_dict(audit_template1, self.SHORT_LIST_FIELDS,
                                  self.SHORT_LIST_FIELD_LABELS)
        ], results)

        self.m_audit_template_mgr.list.assert_called_once_with(
            detail=False,
            strategy='2cf86250-d309-4b81-818e-1537f3dba6e5',
        )