def test_api_20_ucs_discover_and_catalog_all(self):
        """
        Tests the UCS Discovery and Catalon All workflow in rackHD
        :return:
        """
        # delete all previously discovered nodes and catalogs
        self.assertTrue(ucs_common.restore_node_utility(), "failed to restore nodes")
        self.assertTrue(ucs_common.restore_obms_utility(), "failed to restore obms")

        initialNodeCount = len(self.get_ucs_node_list())
        expected_ucs_logical_nodes = ucs_common.get_service_profile_count()
        expected_ucs_physical_nodes = ucs_common.get_physical_server_count()

        data_payload = {
            "name": "Graph.Ucs.Discovery",
            "options": {
                "defaults": {
                    "username": ucs_common.UCSM_USER,
                    "password": ucs_common.UCSM_PASS,
                    "ucs": ucs_common.UCSM_IP,
                    "uri": ucs_common.UCS_SERVICE_URI
                },
                "when-discover-physical-ucs": {
                    "discoverPhysicalServers": "true",
                },
                "when-discover-logical-ucs": {
                    "discoverLogicalServer": "true"
                },
                "when-catalog-ucs": {
                    "autoCatalogUcs": "true"
                }
            }
        }

        header = {"Content-Type": "application/json"}
        api_data = fit_common.rackhdapi("/api/2.0/workflows", action="post",
                                        headers=header, payload=data_payload)
        id = api_data["json"]["context"]["graphId"]
        self.assertEqual(api_data['status'], 201,
                         'Incorrect HTTP return code, expected 201, got:' + str(api_data['status']))
        status = ucs_common.wait_utility(str(id), 0, "Discovery", 240)
        self.assertEqual(status, 'succeeded', 'Discovery graph returned status {}'.format(status))

        newNodeCount = len(self.get_ucs_node_list())

        logs.info_1("Found {0} Nodes after cataloging the UCS".format(len(api_data['json'])))

        self.assertEqual(newNodeCount - initialNodeCount,
                         expected_ucs_physical_nodes + expected_ucs_logical_nodes,
                         'Expected to discover {0} UCS nodes, got: {1}'
                         .format(expected_ucs_physical_nodes + expected_ucs_logical_nodes,
                                 newNodeCount - initialNodeCount))
 def tearDownClass(cls):
     if not ucs_common.restore_node_utility():
         raise Exception("error restoring node list")
     if not ucs_common.restore_obms_utility():
         raise Exception("error restoring obms list")
    def test_api_20_ucs_serviceProfile_discovery(self):
        """
        Tests the UCS Service Profile Discovery workflow in rackHD
        :return:
        """
        # delete all previously discovered nodes and catalogs
        self.assertTrue(ucs_common.restore_node_utility(),
                        "failed to restore nodes")
        self.assertTrue(ucs_common.restore_obms_utility(),
                        "failed to restore obms")

        expected_ucs_logical_nodes = ucs_common.get_service_profile_count()
        if (expected_ucs_logical_nodes == 0):
            raise unittest.SkipTest("No Service Profiles Defined")

        initialNodeCount = len(self.get_ucs_node_list())

        data_payload = {
            "name": "Graph.Ucs.Discovery",
            "options": {
                "defaults": {
                    "username": ucs_common.UCSM_USER,
                    "password": ucs_common.UCSM_PASS,
                    "ucs": ucs_common.UCSM_IP,
                    "uri": ucs_common.UCS_SERVICE_URI
                },
                "when-discover-physical-ucs": {
                    "discoverPhysicalServers": "false",
                },
                "when-discover-logical-ucs": {
                    "discoverLogicalServer": "true"
                },
                "when-catalog-ucs": {
                    "autoCatalogUcs": "false"
                }
            }
        }

        header = {"Content-Type": "application/json"}
        api_data = fit_common.rackhdapi("/api/2.0/workflows",
                                        action="post",
                                        headers=header,
                                        payload=data_payload)
        self.assertEqual(
            api_data['status'], 201,
            'Incorrect HTTP return code, expected 201, got:' +
            str(api_data['status']))
        id = api_data["json"]["context"]["graphId"]
        status = ucs_common.wait_utility(str(id), 0,
                                         "Service Profile Discovery")
        self.assertEqual(
            status, 'succeeded',
            'Service Profile Discovery graph returned status {}'.format(
                status))

        newNodeCount = len(self.get_ucs_node_list())

        self.assertEqual(
            newNodeCount - initialNodeCount, expected_ucs_logical_nodes,
            'Expected to discover {0} UCS nodes, got: {1}'.format(
                expected_ucs_logical_nodes, newNodeCount - initialNodeCount))
        logs.info_1("Found {0} UCS nodes {1}".format(
            len(self.UCS_COMPUTE_NODES), self.UCS_COMPUTE_NODES))

        # rerun discovery graph and verify duplicate nodes are not created
        api_data = fit_common.rackhdapi("/api/2.0/workflows",
                                        action="post",
                                        headers=header,
                                        payload=data_payload)
        id = api_data["json"]["context"]["graphId"]
        self.assertEqual(
            api_data['status'], 201,
            'Incorrect HTTP return code, expected 201, got:' +
            str(api_data['status']))
        status = ucs_common.wait_utility(str(id), 0,
                                         "Service Profile Discovery")
        self.assertEqual(
            status, 'succeeded',
            'Service Profile Discovery graph returned status {}'.format(
                status))

        newNodeCount = len(self.get_ucs_node_list())
        self.assertGreaterEqual(
            newNodeCount - initialNodeCount, 0,
            'Expected to discover {0} UCS nodes, got: {1}'.format(
                0, newNodeCount - initialNodeCount))
 def tearDownClass(cls):
     if not ucs_common.restore_node_utility():
         raise Exception("error restoring node list")
     if not ucs_common.restore_obms_utility():
         raise Exception("error restoring obms list")
    def test_api_20_ucs_serviceProfile_discovery(self):
        """
        Tests the UCS Service Profile Discovery workflow in rackHD
        :return:
        """
        # delete all previously discovered nodes and catalogs
        self.assertTrue(ucs_common.restore_node_utility(), "failed to restore nodes")
        self.assertTrue(ucs_common.restore_obms_utility(), "failed to restore obms")

        expected_ucs_logical_nodes = ucs_common.get_service_profile_count()
        if (expected_ucs_logical_nodes == 0):
            raise unittest.SkipTest("No Service Profiles Defined")

        initialNodeCount = len(self.get_ucs_node_list())

        data_payload = {
            "name": "Graph.Ucs.Discovery",
            "options": {
                "defaults": {
                    "username": ucs_common.UCSM_USER,
                    "password": ucs_common.UCSM_PASS,
                    "ucs": ucs_common.UCSM_IP,
                    "uri": ucs_common.UCS_SERVICE_URI
                },
                "when-discover-physical-ucs": {
                    "discoverPhysicalServers": "false",
                },
                "when-discover-logical-ucs": {
                    "discoverLogicalServer": "true"
                },
                "when-catalog-ucs": {
                    "autoCatalogUcs": "false"
                }
            }
        }

        header = {"Content-Type": "application/json"}
        api_data = fit_common.rackhdapi("/api/2.0/workflows", action="post",
                                        headers=header, payload=data_payload)
        self.assertEqual(api_data['status'], 201,
                         'Incorrect HTTP return code, expected 201, got:' + str(api_data['status']))
        id = api_data["json"]["context"]["graphId"]
        status = ucs_common.wait_utility(str(id), 0, "Service Profile Discovery")
        self.assertEqual(status, 'succeeded', 'Service Profile Discovery graph returned status {}'.format(status))

        newNodeCount = len(self.get_ucs_node_list())

        self.assertEqual(newNodeCount - initialNodeCount,
                         expected_ucs_logical_nodes,
                         'Expected to discover {0} UCS nodes, got: {1}'
                         .format(expected_ucs_logical_nodes, newNodeCount - initialNodeCount))
        logs.info_1("Found {0} UCS nodes {1}".format(len(self.UCS_COMPUTE_NODES), self.UCS_COMPUTE_NODES))

        # rerun discovery graph and verify duplicate nodes are not created
        api_data = fit_common.rackhdapi("/api/2.0/workflows", action="post",
                                        headers=header, payload=data_payload)
        id = api_data["json"]["context"]["graphId"]
        self.assertEqual(api_data['status'], 201,
                         'Incorrect HTTP return code, expected 201, got:' + str(api_data['status']))
        status = ucs_common.wait_utility(str(id), 0, "Service Profile Discovery")
        self.assertEqual(status, 'succeeded', 'Service Profile Discovery graph returned status {}'.format(status))

        newNodeCount = len(self.get_ucs_node_list())
        self.assertGreaterEqual(newNodeCount - initialNodeCount, 0,
                                'Expected to discover {0} UCS nodes, got: {1}'
                                .format(0, newNodeCount - initialNodeCount))