Exemple #1
0
    def check_all_server_power_state(self, state):
        """
        Test to see if all Associated servers are in the specified state
        :return: True or False
        """

        url, headers = self.ucs_url_factory("serviceProfile")
        api_data = fit_common.restful(url, rest_headers=headers)
        self.assertEqual(
            api_data['status'], 200,
            'Incorrect HTTP return code, expected 200, got:' +
            str(api_data['status']))
        total_elements = 0
        for server in api_data["json"]["ServiceProfile"]["members"]:
            if server["assoc_state"] == "associated":
                url, headers = self.ucs_url_factory("power",
                                                    identifier=str(
                                                        server["path"]))
                api_data_c = fit_common.restful(url, rest_headers=headers)
                self.assertEqual(
                    api_data_c['status'], 200,
                    'Incorrect HTTP return code, expected 200, got:' +
                    str(api_data_c['status']))
                self.assertEqual(
                    api_data_c["json"]["serverState"], state, 'Server ' +
                    str(server["path"]) + ' reported power state ' +
                    str(api_data_c["json"]["serverState"]) + ' expected: ' +
                    state)
            total_elements += 1
        self.assertGreater(total_elements, 0, "Found zero elements")
Exemple #2
0
    def get_physical_server_count(self):
        """
        Get a count of the number of Service Proviles defined by the UCS Manager
        """
        url = UCS_SERVICE_URI + "/rackmount"

        headers = {
            "ucs-user": UCSM_USER,
            "ucs-password": UCSM_PASS,
            "ucs-host": UCSM_IP
        }

        api_data = fit_common.restful(url, rest_headers=headers)
        if api_data['status'] != 200:
            logs.error(
                'Incorrect HTTP return code, expected 200, got: {0}'.format(
                    api_data['status']))
            return 0

        count = len(api_data["json"])

        url = UCS_SERVICE_URI + "/chassis"
        api_data = fit_common.restful(url, rest_headers=headers)
        if api_data['status'] != 200:
            logs.error(
                'Incorrect HTTP return code, expected 200, got: {0}'.format(
                    api_data['status']))
            return 0

        count += len(api_data["json"])
        for element in api_data["json"]:
            count += len(element["members"])

        return count
Exemple #3
0
    def test_api_20_ucs_get_catalog(self):
        """
        Test the /sys ucs API
        :return:
        """
        url, headers = self.ucs_url_factory("sys")
        api_data = fit_common.restful(url, rest_headers=headers)
        self.assertEqual(
            api_data['status'], 200,
            'Incorrect HTTP return code, expected 200, got:' +
            str(api_data['status']))
        total_elements = 0
        for elementTypes in api_data["json"]:
            for element in api_data["json"][str(elementTypes)]:
                url, headers = self.ucs_url_factory(
                    "catalog",
                    identifier=element["relative_path"].split("/")[-1])
                api_data_c = fit_common.restful(url, rest_headers=headers)
                self.assertEqual(
                    api_data_c['status'], 200,
                    'Incorrect HTTP return code, expected 200, got:' +
                    str(api_data_c['status']))
                total_elements += 1

        self.assertGreater(total_elements, 0, "Zero catalog elements found")
Exemple #4
0
 def test_api_20_ucs_get_catalog(self):
     """
     Test the /sys ucs API
     :return:
     """
     url = self.ucs_url_factory("sys")
     api_data = fit_common.restful(url)
     self.assertEqual(
         api_data['status'], 200,
         'Incorrect HTTP return code, expected 200, got:' +
         str(api_data['status']))
     total_elements = 0
     for elementTypes in api_data["json"]:
         for element in api_data["json"][str(elementTypes)]:
             url = self.ucs_url_factory(
                 "catalog",
                 identifier=element["relative_path"].split("/")[-1])
             api_data_c = fit_common.restful(url)
             self.assertEqual(
                 api_data['status'], 200,
                 'Incorrect HTTP return code, expected 200, got:' +
                 str(api_data_c['status']))
             total_elements += 1
     self.assertGreaterEqual(
         total_elements, 15,
         "Expected at least 15 elements but found {0}".format(
             total_elements))
    def get_physical_server_count(self):
        """
        Get a count of the number of Service Proviles defined by the UCS Manager
        """
        url = UCS_SERVICE_URI + "/rackmount"

        headers = {"ucs-user": UCSM_USER,
                   "ucs-password": UCSM_PASS,
                   "ucs-host": UCSM_IP}

        api_data = fit_common.restful(url, rest_headers=headers)
        if api_data['status'] != 200:
            logs.error('Incorrect HTTP return code, expected 200, got: {0}'.format(api_data['status']))
            return 0

        count = len(api_data["json"])

        url = UCS_SERVICE_URI + "/chassis"
        api_data = fit_common.restful(url, rest_headers=headers)
        if api_data['status'] != 200:
            logs.error('Incorrect HTTP return code, expected 200, got: {0}'.format(api_data['status']))
            return 0

        count += len(api_data["json"])
        for element in api_data["json"]:
            count += len(element["members"])

        return count
Exemple #6
0
    def set_all_server_power_state(self, state):
        """
        Use the POST /power ucs API to set the state of all servers
        :return:
        """

        url, headers = self.ucs_url_factory("serviceProfile")
        api_data = fit_common.restful(url, rest_headers=headers)
        self.assertEqual(
            api_data['status'], 200,
            'Incorrect HTTP return code, expected 200, got:' +
            str(api_data['status']))
        total_elements = 0
        for server in api_data["json"]["ServiceProfile"]["members"]:
            if server["assoc_state"] == "associated":
                url, headers = self.ucs_url_factory("power",
                                                    identifier=str(
                                                        server["path"]))
                api_data_c = fit_common.restful(url + "&action=" + state,
                                                rest_headers=headers,
                                                rest_action='post')
                self.assertEqual(
                    api_data_c['status'], 200,
                    'Incorrect HTTP return code, expected 200, got:' +
                    str(api_data_c['status']))
            total_elements += 1
        self.assertGreater(total_elements, 0, "Found zero elements")
Exemple #7
0
    def test_ucs_get_sys(self):
        """
        Test the /sys ucs API
        :return:
        """
        url = self.ucs_url_factory("sys")
        api_data = fit_common.restful(url)
        self.assertEqual(
            api_data['status'], 200,
            'Incorrect HTTP return code, expected 200, got:' +
            str(api_data['status']))

        self.assertEqual(
            len(api_data["json"]["Fabric Interconnects"]), 2,
            "Expected 2 Fabric Interconnects but found {0}".format(
                len(api_data["json"]["Fabric Interconnects"])))
        self.assertEqual(
            len(api_data["json"]["Servers"]), 7,
            "Expected 7 Servers but found {0}".format(
                len(api_data["json"]["Servers"])))
        self.assertEqual(
            len(api_data["json"]["FEX"]),
            2, "Expected 2 FEX but found {0}".format(
                len(api_data["json"]["FEX"])))
        self.assertEqual(
            len(api_data["json"]["Chassis"]), 4,
            "Expected 2 Chassis but found {0}".format(
                len(api_data["json"]["Chassis"])))
Exemple #8
0
 def test_api_20_ucs_get_catalog(self):
     """
     Test the /sys ucs API
     :return:
     """
     url, headers = self.ucs_url_factory("sys")
     api_data = fit_common.restful(url, rest_headers=headers)
     self.assertEqual(api_data['status'], 200,
                      'Incorrect HTTP return code, expected 200, got:' + str(api_data['status']))
     total_elements = 0
     for elementTypes in api_data["json"]:
         for element in api_data["json"][str(elementTypes)]:
             url, headers = self.ucs_url_factory("catalog", identifier=element["relative_path"].split("/")[-1])
             api_data_c = fit_common.restful(url, rest_headers=headers)
             self.assertEqual(api_data_c['status'], 200,
                              'Incorrect HTTP return code, expected 200, got:' + str(api_data_c['status']))
             total_elements += 1
     self.assertEqual(total_elements, 15, "Expected 15 elements but found {0}"
                             .format(total_elements))
Exemple #9
0
 def test_ucs_get_rackmount(self):
     """
     Test the /rackmount ucs API
     :return:
     """
     url, headers = self.ucs_url_factory("rackmount")
     api_data = fit_common.restful(url, rest_headers=headers)
     self.assertEqual(api_data['status'], 200,
                      'Incorrect HTTP return code, expected 200, got:' + str(api_data['status']))
     self.assertGreater(len(api_data["json"]), 0, "Found zero Rackmounts")
Exemple #10
0
    def set_all_server_power_state(self, state):
        """
        Use the POST /power ucs API to set the state of all servers
        :return:
        """

        url, headers = self.ucs_url_factory("serviceProfile")
        api_data = fit_common.restful(url, rest_headers=headers)
        self.assertEqual(api_data['status'], 200,
                         'Incorrect HTTP return code, expected 200, got:' + str(api_data['status']))
        total_elements = 0
        for server in api_data["json"]["ServiceProfile"]["members"]:
            url, headers = self.ucs_url_factory("power", identifier=str(server["path"]))
            api_data_c = fit_common.restful(url + "&action=" + state, rest_headers=headers, rest_action='post')
            self.assertEqual(api_data_c['status'], 200,
                             'Incorrect HTTP return code, expected 200, got:' + str(api_data_c['status']))
            total_elements += 1
        self.assertEqual(total_elements, 18, "Expected 18 elements but found {0}"
                         .format(total_elements))
Exemple #11
0
 def test_ucs_get_chassis(self):
     """
         Test the /chassis ucs API
         :return:
         """
     url = self.ucs_url_factory("chassis")
     api_data = fit_common.restful(url)
     self.assertEqual(api_data['status'], 200,
                      'Incorrect HTTP return code, expected 200, got:' + str(api_data['status']))
     self.assertGreaterEqual(len(api_data["json"]), 4, "Expected 4 chassis or more but found {0}".
                             format(len(api_data["json"])))
Exemple #12
0
 def test_ucs_get_serviceProfile(self):
     """
     Test the /serviceProfile ucs API
     :return:
     """
     url, headers = self.ucs_url_factory("serviceProfile")
     api_data = fit_common.restful(url, rest_headers=headers)
     self.assertEqual(api_data['status'], 200,
                      'Incorrect HTTP return code, expected 200, got:' + str(api_data['status']))
     if len(api_data["json"]["ServiceProfile"]["members"]) == 0:
         raise unittest.SkipTest("No Service Profiles Defined")
Exemple #13
0
    def test_ucs_get_chassis(self):
        """
        Test the /chassis ucs API
        :return:
        """
        url, headers = self.ucs_url_factory("chassis")
        api_data = fit_common.restful(url, rest_headers=headers)
        self.assertEqual(api_data['status'], 200,
                         'Incorrect HTTP return code, expected 200, got:' + str(api_data['status']))

        self.assertGreater(len(api_data["json"]), 0, "Zero chassis elements found")
Exemple #14
0
 def test_ucs_get_rackmount(self):
     """
     Test the /rackmount ucs API
     :return:
     """
     url, headers = self.ucs_url_factory("rackmount")
     api_data = fit_common.restful(url, rest_headers=headers)
     self.assertEqual(api_data['status'], 200,
                      'Incorrect HTTP return code, expected 200, got:' + str(api_data['status']))
     self.assertEqual(len(api_data["json"]), 7, "Expected 7 Rackmounts but found {0}".
                             format(len(api_data["json"])))
Exemple #15
0
 def test_ucs_get_chassis(self):
     """
     Test the /chassis ucs API
     :return:
     """
     url, headers = self.ucs_url_factory("chassis")
     api_data = fit_common.restful(url, rest_headers=headers)
     self.assertEqual(api_data['status'], 200,
                      'Incorrect HTTP return code, expected 200, got:' + str(api_data['status']))
     self.assertEqual(len(api_data["json"]), 4, "Expected 4 chassis but found {0}".
                             format(len(api_data["json"])))
Exemple #16
0
    def test_ucs_log_in(self):
        """
        Test the /logIn ucs API
        :return:
        """
        url, headers = self.ucs_url_factory("login")
        api_data = fit_common.restful(url, rest_headers=headers)
        self.assertEqual(api_data['status'], 200,
                         'Incorrect HTTP return code, expected 200, got:' + str(api_data['status']))

        self.assertNotEqual(api_data["json"], None, "Expected a token to be returned on login and received None")
        self.assertNotEqual(type(api_data["json"]), "unicode", "Unexpected Token was received on Login")
Exemple #17
0
 def test_ucs_get_serviceProfile(self):
     """
     Test the /serviceProfile ucs API
     :return:
     """
     url, headers = self.ucs_url_factory("serviceProfile")
     api_data = fit_common.restful(url, rest_headers=headers)
     self.assertEqual(api_data['status'], 200,
                      'Incorrect HTTP return code, expected 200, got:' + str(api_data['status']))
     self.assertEqual(len(api_data["json"]["ServiceProfile"]["members"]), 18,
                      "Expected 18 chassis or more but found {0}"
                      .format(len(api_data["json"]["ServiceProfile"]["members"])))
Exemple #18
0
    def check_all_server_power_state(self, state):
        """
        Test to see if all Associated servers are in the specified state
        :return: True or False
        """

        url, headers = self.ucs_url_factory("serviceProfile")
        api_data = fit_common.restful(url, rest_headers=headers)
        self.assertEqual(api_data['status'], 200,
                         'Incorrect HTTP return code, expected 200, got:' + str(api_data['status']))
        total_elements = 0
        for server in api_data["json"]["ServiceProfile"]["members"]:
            url, headers = self.ucs_url_factory("power", identifier=str(server["path"]))
            api_data_c = fit_common.restful(url, rest_headers=headers)
            self.assertEqual(api_data_c['status'], 200,
                             'Incorrect HTTP return code, expected 200, got:' + str(api_data_c['status']))
            self.assertEqual(api_data_c["json"]["serverState"], state,
                             'Server ' + str(server["path"]) + ' reported power state ' +
                             str(api_data_c["json"]["serverState"]) + ' expected: ' + state)
            total_elements += 1
        self.assertEqual(total_elements, 18, "Expected 18 elements but found {0}"
                         .format(total_elements))
Exemple #19
0
    def get_service_profile_count(self):
        """
        Get a count of the number of Service Proviles defined by the UCS Manager
        """
        url = UCS_SERVICE_URI + "/serviceProfile"
        headers = {"ucs-user": UCSM_USER,
                   "ucs-password": UCSM_PASS,
                   "ucs-host": UCSM_IP}

        api_data = fit_common.restful(url, rest_headers=headers)
        self.assertEqual(api_data['status'], 200,
                         'Incorrect HTTP return code, expected 200, got:' + str(api_data['status']))

        return len(api_data["json"]["ServiceProfile"]["members"])
Exemple #20
0
def get_service_profile_count():
    """
    Get a count of the number of Service Proviles defined by the UCS Manager
    """
    url = UCS_SERVICE_URI + "/serviceProfile"
    headers = {"ucs-user": UCSM_USER,
               "ucs-password": UCSM_PASS,
               "ucs-host": UCSM_IP}

    api_data = fit_common.restful(url, rest_headers=headers)
    if api_data['status'] != 200:
        logs.error('Incorrect HTTP return code, expected 200, got: {0}'.format(api_data['status']))
        return 0

    return len(api_data["json"]["ServiceProfile"]["members"])
Exemple #21
0
 def test_ucs_get_rackmount(self):
     """
     Test the /rackmount ucs API
     :return:
     """
     url = self.ucs_url_factory("rackmount")
     api_data = fit_common.restful(url)
     self.assertEqual(
         api_data['status'], 200,
         'Incorrect HTTP return code, expected 200, got:' +
         str(api_data['status']))
     self.assertGreaterEqual(
         len(api_data["json"]), 1,
         "Expected 1  or more Rackmounts but found {0}".format(
             len(api_data["json"])))
Exemple #22
0
def get_service_profile_count():
    """
    Get a count of the number of Service Proviles defined by the UCS Manager
    """
    url = UCS_SERVICE_URI + "/serviceProfile"
    headers = {"ucs-user": UCSM_USER,
               "ucs-password": UCSM_PASS,
               "ucs-host": UCSM_IP}

    api_data = fit_common.restful(url, rest_headers=headers)
    if api_data['status'] != 200:
        logs.error('Incorrect HTTP return code, expected 200, got: {0}'.format(api_data['status']))
        return 0

    return len(api_data["json"]["ServiceProfile"]["members"])
Exemple #23
0
    def test_ucs_get_sys(self):
        """
        Test the /sys ucs API
        :return:
        """
        url, headers = self.ucs_url_factory("sys")
        api_data = fit_common.restful(url, rest_headers=headers)
        self.assertEqual(api_data['status'], 200,
                         'Incorrect HTTP return code, expected 200, got:' + str(api_data['status']))

        self.assertIn("Fabric Interconnects", api_data["json"], "Results did not contain 'Fabric Interconnects'")

        self.assertIn("Servers", api_data["json"], "Results did not contain 'Servers")

        self.assertIn("FEX", api_data["json"], "Results did not contain 'FEX")

        self.assertIn("Chassis", api_data["json"], "Results did not contain 'Chassis")
Exemple #24
0
    def test_ucs_get_sys(self):
        """
        Test the /sys ucs API
        :return:
        """
        url, headers = self.ucs_url_factory("sys")
        api_data = fit_common.restful(url, rest_headers=headers)
        self.assertEqual(api_data['status'], 200,
                         'Incorrect HTTP return code, expected 200, got:' + str(api_data['status']))

        self.assertEqual(len(api_data["json"]["Fabric Interconnects"]), 2,
                         "Expected 2 Fabric Interconnects but found {0}"
                         .format(len(api_data["json"]["Fabric Interconnects"])))
        self.assertEqual(len(api_data["json"]["Servers"]), 7, "Expected 7 Servers but found {0}"
                         .format(len(api_data["json"]["Servers"])))
        self.assertEqual(len(api_data["json"]["FEX"]), 2, "Expected 2 FEX but found {0}"
                         .format(len(api_data["json"]["FEX"])))
        self.assertEqual(len(api_data["json"]["Chassis"]), 4, "Expected 2 Chassis but found {0}"
                         .format(len(api_data["json"]["Chassis"])))