def DCS_change_fan_status(ipaddr, bay_number, enclosure_id, status):
    """
        Change an enclosure's fan status in DCS. Works for C7000 only.
    """

    logger._log_to_console("\n- Setting status " + status +
                           " to Fanbay number " + bay_number)
    if status not in DCSConstants.FAN_OP_STATUS_LIST:
        ui_lib.fail_test(
            "\nInvalid status [%s] for enclosure's fan. Valid values are: %s" %
            (status, DCSConstants.FAN_OP_STATUS_LIST), False)

    # mount URL based on the informed enclosure id
    url_dcs_instance = "http://" + str(
        ipaddr[8:]
    ) + DCSConstants.DCS_PORT + DCSConstants.DCS_REST_INSTANCES + "/" + enclosure_id

    # create the URI to change the fan status
    changeFanURI = url_dcs_instance + "?action=changeFanStatus&bayNum=" + bay_number + "&operationalStatus=" + status
    logger._log_to_console("\t- URI: " + changeFanURI)
    response = requests.post(changeFanURI, stream=True)

    if (response.status_code == DCSConstants.HTTP_STATUS_CODE_OK):
        logger._log_to_console_and_log_file(
            "\t- Fan status changed successfully.")
    else:
        ui_lib.fail_test("\tChange fan status failed: " + response.content,
                         False)
Beispiel #2
0
    def _untaken_transitions_in_state(self, state):
        '''
        List of untaken transitions in given state(uses flattened states)
        '''
        logging._debug("Calling _untaken_transitions_in_state")
        logging._debug("Got State: '%s'" % state)

        if (not isinstance(state, str)):
            state = self._flatten_state(state)

        if self.debug:
            logging._log_to_console(
                "Looking for untaken transitions in state: %s" %
                pprint.pformat(state))

        transitions = self.flat_model[state]
        untaken = []

        for transition in transitions:
            if '-taken' not in transition:
                if self.debug:
                    logging._log_to_console("Found untaken transition: %s" %
                                            pprint.pformat(transition))
                untaken.append(transition)

        if self.debug:
            logging._info("_untaken_transitions_in_state returning: %s" %
                          pprint.pformat(untaken))
        return untaken
Beispiel #3
0
 def _set_checksum(self):
     """
     Retrieve and set the checksum variable. The method assumes that all
     OneView artifacts checksums is stored in .sha256 file.
     :return:
     """
     _link = self.url + '.sha256'
     r = self.http.request('GET', _link)
     if r.status == 200:
         self.c_sum = r.data.split()[0]
         m = "INFO: Checksum information {}".format(r.data)
         log._log_to_console_and_log_file(m)
     else:
         m = "WARN: Checksum information unavailable"
         log._log_to_console(m)
def login(user_name):
    s2l = ui_lib.get_s2l()
    logger._log_to_console('Login status = {0}'.format(str(base_page.logged_in())))

    if base_page.logged_in():
        base_page.logout()

    user = test_data.get_user_by_name(user_name)

    # check the existing login status
    logger._log_to_console_and_log_file("Logging into i3S as {0}/{1}".format(user.name, user.password))
    if s2l._is_element_present(i3SLoginPage.ID_BTN_EULA_AGREE):
        s2l.click_button(i3SLoginPage.ID_BTN_EULA_AGREE)

    s2l.wait_until_page_contains_element(i3SLoginPage.ID_BTN_LOGIN_BUTTON)
    s2l.input_text(i3SLoginPage.ID_INPUT_LOGIN_USER, user.name)
    s2l.input_text(i3SLoginPage.ID_INPUT_LOGIN_PASSWORD, user.password)

    # code to login as  active directory user
    if(user.has_property("domainName")):
        s2l.click_element(i3SLoginPage.ID_ELEMENT_AUTHN_PROVIDER)
        dirListObj = i3SLoginPage.ID_ELEMENT_DIR % user.domainName.strip()

        s2l.click_element(dirListObj)
        activedir = s2l.get_text(i3SLoginPage.ID_COMBO_AUTHN_PROVIDER)
        if not activedir == user.domainName.strip():
            logger._warn("Not able to login to the appliance with active directory users ..")
            ui_lib.fail_test("not able to login as active directory users... verify AD users and groups is added to the appliance")

    s2l.click_button(i3SLoginPage.ID_BTN_LOGIN_BUTTON)
    # These elements may not exist if the login page is transitioning to the dashboard
    # page.  In order to avoid failing conditions, we will catch any exceptions
    try:
        s2l.element_should_not_be_visible(i3SLoginPage.ID_ALL_ERROR_FIELDS)
        s2l.element_text_should_be(i3SLoginPage.ID_LABEL_LOGIN_STATUS, "")
    except:
        pass

    s2l.wait_until_page_contains_element(i3SDashboardPage.ID_PAGE_LABEL,
                                         UiConstants.i3S_LOGIN_TIME,
                                         "Failed to load the Login Page")
    base_page.set_logged_user(user_name)
    logger._log_to_console_and_log_file("Logged into i3S as {0}".format(base_page.get_logged_user()))
    return True
Beispiel #5
0
    def _cond_met(self, trans, states):
        '''
        Returns true if transition conditions are met
        '''
        # If no cond, then conditions are met
        if 'cond' not in trans:
            return True

        ins = []
        cond = copy.deepcopy(trans['cond'])

        # Evaluate each in predicate
        regex = re.compile("In\([\"\'](\S+)[\"\']\)", re.IGNORECASE)
        matches = regex.findall(cond)
        if self.debug:
            logging._log_to_console("Found Matches: %s" %
                                    pprint.pformat(matches))

        # for match in regex.finditer(cond):
        for match in matches:
            zin = 0
            for state in states:
                if (state['id'] == match) or (match in state['-hierarchy']):
                    zin = 1
                    break
            ins.append(zin)

        if len(ins) == 0:
            if self.debug:
                logging._log_to_console("ins: %s" % pprint.pformat(ins))
            raise AttributeError("Failed to find 'In' predicate in cond '%s'" %
                                 cond)

        # Replace each In predicate with True or False
        for val in ins:
            cond = regex.sub(str(val), cond, 1)

        # TODO: Replace any '!'s with 'not'
        regex = re.compile("\!")
        cond = regex.sub('not ', cond)

        # Evaluate Condition
        if self.debug:
            logging._log_to_console("_cond_met eval string: %s" % cond)
        cond_val = eval(cond)

        if self.debug:
            logging._log_to_console("_cond_met returning %s" % bool(cond_val))
        return bool(cond_val)
Beispiel #6
0
def ipdu_power_control(server, xml, port=50443):
    """ iPDU Power Control creates connection over the socket and send the XML commands to the iPDU via the xml file.

        server: The IP Address (or FQDN) of iPDU
        xml: XML file containing containing iPDU commands
        port: Port for XML queries is 50443
        Example:
        | iPDU Power Control      | ${server} | ${xml} | ${port} |
    """
    try:
        logging._log_to_console("Connecting to iPDU server %s:%s" %
                                (server, port))
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.connect((server, port))
    except socket.error as msg:
        s.close()
        s = None

    if s is None:
        raise AssertionError('Could not open socket!')

    ins = open(xml, "r")

    ssl_sock = ssl.wrap_socket(s, ssl_version=ssl.PROTOCOL_SSLv3)

    for line in ins:
        # write line by line to iPDU server
        logging._log_to_console_and_log_file(
            "Send XML data to iPDU server %s" % line)
        ssl_sock.write(line)

        # Read a chunk of data.  Will not necessarily
        # read all the data returned by the server.
    data = ssl_sock.read()

    # Note that you need to close the underlying socket, not the SSL object.
    del ssl_sock
    s.close()
Beispiel #7
0
    def _transitions_to_needed_state(self, states, ttl=None):
        '''
        Transition to a state with untaken transitions
        '''
        logging._debug("Calling _transitions_to_needed_state")

        # None needed if there are untaken transitions from current state(s)
        if self._untaken_transitions_in_state(states):
            if self.debug:
                logging._log_to_console(
                    "There are untaken transitions in this state.\n")
            return []

        # Longest possible number of needed transitions
        if ttl is None:
            ttl = self._number_of_flat_states()

        # Increase number of transitions to take to find path to needed
        # state(s)
        for depth in range(1, ttl + 1):
            for trans in self._available_transitions(states):
                if 'target' not in trans:
                    continue

                # Check each transition from this state
                nextStates = self._get_next_state(states, trans)
                transitions = self._transitions_to_needed_state(
                    nextStates, depth - 1)
                # FIXME: This can be done better
                if transitions is not None:
                    ret = [trans]
                    ret.extend(transitions)
                    return ret

        # Unable to get to needed state from in $ttl transitions
        return None
Beispiel #8
0
 def _untaken_transitions(self):
     '''
     Are there untaken transitions?
     '''
     if self.debug:
         logging._log_to_console("\nAre there untaken transitions?")
     for state in self.flat_model.keys():
         if self._untaken_transitions_in_state(state):
             if self.debug:
                 logging._log_to_console("There are untaken transitions\n")
             return 1
     if self.debug:
         logging._log_to_console("No untaken transitions\n")
     return 0
 def i3s_get_deploymentplan(self, uri=None, api=None, headers=None, param=''):
     logger._log_to_console("Value in dp param in getcall for all artifacts is" +str(param))
     if api:
         headers = self.i3s_client._set_req_api_version(api=api)
     elif not headers:
         headers = self.i3s_client._headers
     if uri:
         uri = 'https://%s%s' % (self.i3s_client._host, uri)
         logger._log_to_console("Value in dp uri in if of getcall for all artifacts is" +str(uri))
     else:
         uri = 'https://%s/rest/deployment-plans/%s' % (self.i3s_client._host, param)        
         logger._log_to_console("Value in dp uri in else of getcall for all artifacts is" +str(uri))
     response = self.i3s_client.get(uri=uri, headers=headers)
     return response
Beispiel #10
0
    def _validate_scxml(self):
        '''
        basic validation of the SCXML
        '''
        xml = self.xml

        # Check basic first tags/attributes
        if 'state' not in xml:
            raise AttributeError("No states?")

        if 'initial' not in self.root.attrib:
            raise AttributeError("No initial attribute for scxml")

        # Check and gather states
        states = self._get_verifiable_states()
        if len(states) == 0:
            raise AttributeError("No verifiable states in SCXML")

        # Gather and check transitions for each state
        events = []
        for state in states:
            if 'transition' not in state:
                print "No transitions in state %s. Skipping." % state
                continue

            for trans in state['transition']:
                if 'event' not in trans:
                    raise AttributeError(
                        "missing event in transition for state %s" %
                        state['id'])

                if 'cond' in trans:
                    match = re.search("In\([\"\']\S+[\"\']\)", trans['cond'],
                                      re.IGNORECASE)
                    if match is None:
                        raise AttributeError(
                            "only supporting conditions with In predicates")

                events.append(trans['event'])

        if len(events) == 0:
            raise AttributeError("no transitions with events?")

        # Validate initial
        if not ('state' in xml) and ([
                1
                for x in xml['state'] if x['id'] == self.root.attrib['initial']
        ]):
            raise AttributeError(
                "failed to find corresponding state tag for initial state")

        # No state id can be 'state' or 'parallel', that's just confusing
        if ([
                1 for state in states
                if (re.search(r"(state|parallel)", state['id'], re.IGNORECASE))
        ]):
            raise NameError("don't make a state id 'state' or 'parallel'")

        # Also can't contain a space
        if ([
                1 for state in states
                if (re.search(r"\s", state['id'], re.IGNORECASE))
        ]):
            raise NameError("state or parallel id can't contain a space")

        # If running in debug mode, skip verification of expected keywords
        if self.debug:
            logging._log_to_console("Skipping expected keyword verification")
            return

        # Skip Keyword validation if specified
        if self.skip_keyword_validation:
            logging._debug("Skipping Keyword Validation.")
            return

        # Validating keywords
        for state in states:
            self.built_in.keyword_should_exist(
                state['id'], "Keyword for state '%s' not found" % state['id'])
        for event in events:
            self.built_in.keyword_should_exist(
                event, "Keyword for event '%s' not found" % event)

        pass
Beispiel #11
0
    def run_all_transitions(
        self,
        type="online",
        file=None,
        minutes=None,
    ):
        '''
        Runs all transitions
        usage: runAllTransitions(minutes, type, file)
         minutes -- maximum number of minutes to run
         type -- online or offline (defaults to onliine)
         file -- file to log transitions
        '''
        path = None
        fh = None
        start = time.time()

        # Validate args
        if (type is None) or (string.lower(type) != "online"
                              and string.lower(type) != "offline"):
            raise AttributeError(
                "run_all_transitions requires 'type' arg set to \
                            offline or online")

        if (string.lower(type) == "offline" and (file is None)):
            raise AttributeError("run_all_transitions requires 'file' arg for \
                            offline run")

        if (string.lower(type) == "offline" and minutes is not None):
            raise AttributeError(
                "can't use 'minutes' constraint in offline test \
                            generation")

        if self.root is None:
            raise AttributeError("can't run_all_transitions without SCXML to \
                            constructor")

        # State with initial state
        curr_states = self._get_full_state(self.root.attrib['initial'])
        self._flatten_state(curr_states)

        if file is None:
            path = []
            for state in curr_states:
                path.append("state: %s" % state['id'])
        else:
            path = file
            fh = open(file, "w")
            for state in curr_states:
                fh.write("state: %s\n" % state['id'])

        # for trans in self._untaken_transitions():
        while self._untaken_transitions():
            if self.debug:
                logging._log_to_console(
                    "=======================================================")
                logging._log_to_console("Now in state: %s\n" %
                                        pprint.pformat(curr_states[0]['id']))

            # Check for exit conditions
            if minutes is not None:
                if (time.time() - start) > (int(minutes) * 60):
                    logging._info(
                        "Time Constraint of %s minutes has been exceeded. Execution complete."
                        % minutes)
                    break

            # Get to closest state with untaken transitions
            transitions = self._transitions_to_needed_state(curr_states)
            if transitions is None:
                state_ids = [state['id'] for state in curr_states]
                raise RuntimeError("Unable to get to needed states from %s" %
                                   ' '.join(state_ids))

            # Log transitions to get to that state
            for trans in transitions:
                curr_states = self._get_next_state(curr_states, trans)
                if file is not None:
                    fh.write("event: %s\n" % trans['event'])
                    # FIXME: Better way to do this
                    for state in curr_states:
                        fh.write("state: %s\n" % state['id'])
                else:
                    path.append("event: %s" % trans['event'])
                    # FIXME: Better way to do this
                    for state in curr_states:
                        path.append("state: %s" % state['id'])

            logging._debug("curr_states: %s" % pprint.pformat(curr_states))

            # Choose an untaken transition
            if self.debug:
                logging._log_to_console("Getting untaken transitions...")
            transitions = self._untaken_transitions_in_state(curr_states)
            if self.debug:
                logging._log_to_console("Selecting from transitions: %s" %
                                        pprint.pformat(transitions))
            trans = transitions[random.randint(0, len(transitions) - 1)]
            trans['-taken'] = 1
            curr_states = self._get_next_state(curr_states, trans)
            self._flatten_state(curr_states)

            if self.debug:
                logging._log_to_console("\nTook transition: %s" %
                                        pprint.pformat(trans))

            # Log it
            if file is not None:
                logging._debug("Writing event '%s' to file." % trans['event'])
                fh.write("event: %s\n" % trans['event'])
                for state in curr_states:
                    logging._debug("Writing state '%s' to file." % state['id'])
                    fh.write("state: %s\n" % state['id'])
            else:
                path.append("event: %s" % trans['event'])
                for state in curr_states:
                    path.append("state: %s" % state['id'])

        if file is not None:
            fh.close()

        # Run this path if online, otherwise done
        if string.lower(type) == "online":
            return self.run_defined_path(path)

        return True
Beispiel #12
0
def create_oedeploymentplan(self, *createoedeploymentplan_obj):
    """ Select Create OEDeploymentplans - Create OEDP for valid input-data 
    check for error messages for invalid data
        Example:
        | Select Create-OEDeploymentplans     |     |
    """
    MAX_CHAR = 255
    s2l = ui_lib.get_s2l()
    """ Navigate to DeploymentPlan Page """

    if not s2l._is_element_present(i3sDeploymentPlanPage.ID_PAGE_LABEL):
        navigate()
    """ Retrieve data from datasheet """
    if type(createoedeploymentplan_obj) is test_data.DataObj:
        createoedeploymentplan_obj = [createoedeploymentplan_obj]
    elif type(createoedeploymentplan_obj) is tuple:
        createoedeploymentplan_obj = list(createoedeploymentplan_obj[0])
    for oedp in createoedeploymentplan_obj:
        ''' In the below code, flags are set/unset based on the validity of the input parameters'''
        ''' Below are flags to track invalid inputs'''
        name_flag = 1
        desc_flag = 1
        gi_flag = 1
        bp_flag = 1
        new_name_flag = 1
        special_char_flag = 1
        exis_gi_flag = 1
        exis_bp_flag = 1

        if re.search('[^a-zA-Z_]', oedp.name):
            special_char_flag = 0
        if (oedp.name == ""):
            name_flag = 0
            special_char_flag = 1
        if (oedp.description == ""):
            desc_flag = 0
        if (oedp.goldenimageuri == ""):
            gi_flag = 0
        if (oedp.oebuildplanuri == ""):
            bp_flag = 0
        """ Before Adding check for the Deploymentplan exists """
        if name_flag:
            if s2l._is_element_present(
                    i3sDeploymentPlanPage.ID_ELEMENT_DEPLOYMENTPLAN %
                    oedp.name):
                '''set new_name_flag to false if name already exists'''
                new_name_flag = 0
        if ui_lib.wait_for_element_and_click(
                i3sDeploymentPlanPage.ID_CREATE_DP_PAGE):
            ui_lib.wait_for_element_visible(
                i3sDeploymentPlanPage.CREATE_OEDP_TITLE)
        ui_lib.wait_for_element_and_input_text(
            i3sDeploymentPlanPage.ID_INPUT_NAME, oedp.name)
        ui_lib.wait_for_element_and_input_text(
            i3sDeploymentPlanPage.ID_INPUT_DESCRIPTION, oedp.description)
        s2l.select_from_list_by_value(
            i3sDeploymentPlanPage.ID_INPUT_OSTYPE_LIST, oedp.ostype)

        if (bp_flag == 1):
            if (oedp.oebuildplanuri != 'non-existing-bp'):
                ui_lib.wait_for_element_and_click(
                    i3sDeploymentPlanPage.ID_INPUT_BUILDPLAN_DROPDOWN)
                ui_lib.wait_for_element_and_click(
                    i3sDeploymentPlanPage.ID_INPUT_BUILDPLAN %
                    oedp.oebuildplanuri)
            else:
                '''set exis_bp_flag to false if we provide non-existing BP uri'''
                exis_bp_flag = 0
                ui_lib.wait_for_element_and_input_text(
                    i3sDeploymentPlanPage.OEDP_INPUT_BP_TEXTBOX,
                    oedp.oebuildplanuri)
            sleep(5)

        if (gi_flag == 1):
            if (oedp.goldenimageuri != 'non-existing-gi'):
                ui_lib.wait_for_element_and_click(
                    i3sDeploymentPlanPage.ID_INPUT_GOLDENIMAGE_DROPDOWN)
                ui_lib.wait_for_element_and_click(
                    i3sDeploymentPlanPage.ID_INPUT_GOLDENIMAGE %
                    oedp.goldenimageuri)
            else:
                '''set exis_gi_flag to false if we provide non-existing GI uri'''
                exis_gi_flag = 0
                ui_lib.wait_for_element_and_input_text(
                    i3sDeploymentPlanPage.OEDP_INPUT_GI_TEXTBOX,
                    oedp.goldenimageuri)
            sleep(5)

        if (oedp.button != 'cancel'):
            '''Creating oedeploymentplan clicking create/create plus'''
            if (oedp.button == 'create'):
                ui_lib.wait_for_element_and_click(
                    i3sDeploymentPlanPage.ID_CREATE_DP_BUTTON)
            elif (oedp.button == 'create+'):
                ui_lib.wait_for_element_and_click(
                    i3sDeploymentPlanPage.ID_CREATEPLUS_DP_BUTTON)
            sleep(5)

            if (gi_flag == 0):
                if not ui_lib.wait_for_element(
                        i3sDeploymentPlanPage.OEDP_BLANK_GI_URL_MESSAGE):
                    logger._warn("BLANK GI MESSAGE not found")
            if (bp_flag == 0):
                if not ui_lib.wait_for_element(
                        i3sDeploymentPlanPage.OEDP_BLANK_BP_URL_MESSAGE):
                    logger._warn("BLANK BP MESSAGE not found")
            ''' if we have provided non-existing BP uri and non-existing GI uri or non-existing GI uri and existing BP uri'''
            if ((exis_gi_flag == 0 and exis_bp_flag == 1)
                    or (exis_gi_flag == 0 and exis_bp_flag == 0)):
                try:
                    if ui_lib.wait_for_element_visible(
                            i3sDeploymentPlanPage.ID_ERROR_FORM):
                        text = ui_lib.get_text(
                            i3sDeploymentPlanPage.ID_ERROR_FORM)
                        if len(
                                ui_lib.get_text(i3sDeploymentPlanPage.
                                                ID_ERROR_FORM).strip()) == 0:
                            logger._warn('Blank error form')
                        elif (text !=
                              error_messages.OEDP_INVALID_GI_URL_MESSAGE):
                            logger._warn(
                                "Error message displayed  doesn't match the invalid golden image error message"
                            )
                            logger._log_to_console_and_log_file(
                                "Error message is" + str(text))
                    else:
                        logger._warn('no error form found')
                except:
                    logger._warn('no error form found')
            ''' if we have provided non-existing BP uri and existing GI uri'''
            if (exis_bp_flag == 0 and exis_gi_flag == 1):
                try:
                    if ui_lib.wait_for_element_visible(
                            i3sDeploymentPlanPage.ID_ERROR_FORM):
                        text = ui_lib.get_text(
                            i3sDeploymentPlanPage.ID_ERROR_FORM)
                        if len(
                                ui_lib.get_text(i3sDeploymentPlanPage.
                                                ID_ERROR_FORM).strip()) == 0:
                            logger._warn('Blank error form')
                        elif (text !=
                              error_messages.OEDP_INVALID_OEBP_URL_MESSAGE):
                            logger._warn(
                                "Error message displayed  doesn't match the invalid build plan error message"
                            )
                            logger._log_to_console("Error message is" +
                                                   str(text))
                    else:
                        logger._warn('no error form found')
                except:
                    logger._warn('no error form found')

            if (name_flag == 0):
                if not ui_lib.wait_for_element(
                        i3sDeploymentPlanPage.ID_BLANK_NAME):
                    logger._warn("Blank name message not found")

            if (len(oedp.name) > MAX_CHAR):
                new_name_flag = 0

            if (desc_flag == 0):
                if not ui_lib.wait_for_element(
                        i3sDeploymentPlanPage.ID_BLANK_DESCRIPTION):
                    logger._warn("Blank description message not found")

            if (new_name_flag == 0):
                try:
                    if ui_lib.wait_for_element_visible(
                            i3sDeploymentPlanPage.ID_ERROR_FORM):
                        text = ui_lib.get_text(
                            i3sDeploymentPlanPage.ID_ERROR_FORM)
                        if len(
                                ui_lib.get_text(i3sDeploymentPlanPage.
                                                ID_ERROR_FORM).strip()) == 0:
                            logger._warn('Blank error form found')
                        elif (text !=
                              error_messages.OEDP_DUPLICATE_NAME_MESSAGE):
                            logger._warn(
                                "duplicate name error message is not displayed"
                            )
                            logger._log_to_console_and_log_file(
                                "Error message is" + str(text))
                except:
                    logger._warn('no error form found')

            if (special_char_flag == 0):
                try:
                    if ui_lib.wait_for_element_visible(
                            i3sDeploymentPlanPage.ID_ERROR_FORM):
                        text = ui_lib.get_text(
                            i3sDeploymentPlanPage.ID_ERROR_FORM)
                        if len(
                                ui_lib.get_text(i3sDeploymentPlanPage.
                                                ID_ERROR_FORM).strip()) == 0:
                            logger._warn('Blank error form')
                        elif (text !=
                              error_messages.OEDP_INVALID_INPUT_MESSAGE):
                            logger._warn(
                                "invalid name error message is not displayed")
                            logger._log_to_console_and_log_file(
                                "Error message is" + str(text))
                except:
                    logger._warn('no error form found')

            if (oedp.button == 'create'):
                if ui_lib.wait_for_element_visible(
                        i3sDeploymentPlanPage.CREATE_OEDP_TITLE):
                    return_to_create_dppage()
                    continue
                elif ui_lib.wait_for_element(
                        i3sDeploymentPlanPage.ID_ELEMENT_DEPLOYMENTPLAN %
                        oedp.name):
                    logger._log_to_console_and_log_file(
                        "Created Deploymentplan %s succeedeed" % oedp.name)
                    continue
                else:

                    logger._warn("Creating Deploymentplan %s failed" %
                                 oedp.name)
                    continue
            if (oedp.button == 'create+'):
                if not ui_lib.wait_for_element_visible(
                        i3sDeploymentPlanPage.CREATE_OEDP_TITLE):
                    logger._warn(
                        "Failed to return to OEDP Create UI, post clicking Create plus"
                    )
                continue
                '''Cancelling creation of oedeploymentplan'''
        elif (oedp.button == 'cancel'):
            ui_lib.wait_for_element_and_click(
                i3sDeploymentPlanPage.ID_CANCEL_DP_BUTTON)
            if ui_lib.wait_for_element_visible(
                    i3sDeploymentPlanPage.ID_CANCEL_CONFIRM_FORM):
                ui_lib.wait_for_element_and_click(
                    i3sDeploymentPlanPage.ID_CANCEL_PROCEED_BUTTON)
            if not ui_lib.wait_for_element(
                    i3sDeploymentPlanPage.ID_PAGE_LABEL):
                logger._warn("Failed to navigate to OE Deployment page")
            continue
    return
Beispiel #13
0
def edit_oedeploymentplan(self, *editoedeploymentplan_obj):
    """ Select Edit DeploymentPalns - Edit OEDP for valid input-data
    check for error messages for invalid data
        Example:
        | Edit Deploymentplans     |     |
    """
    MAX_CHAR = 255
    s2l = ui_lib.get_s2l()
    """ Navigate to DeploymentPlan Page """
    if not s2l._is_element_present(i3sDeploymentPlanPage.ID_PAGE_LABEL):
        navigate()
    """ Retrieve data from datasheet """
    if type(editoedeploymentplan_obj) is test_data.DataObj:
        editoedeploymentplan_obj = [editoedeploymentplan_obj]
    elif type(editoedeploymentplan_obj) is tuple:
        editoedeploymentplan_obj = list(editoedeploymentplan_obj[0])
        newName_var = "newName"
        desc_var = "description"
        goldenimage_var = "goldenimageuri"
        oebuildplan_var = "oebuildplanuri"
        ostype_var = "ostype"
    for oedp in editoedeploymentplan_obj:
        ''' Below are flags to track invalid inputs'''
        name_flag = 1
        desc_flag = 1
        gi_flag = 1
        bp_flag = 1
        new_name_flag = 1
        special_char_flag = 1
        exis_gi_flag = 1
        exis_bp_flag = 1
        """ Before Editing check if the Deploymentplan exists """
        if s2l._page_contains(oedp.name):
            oedp_Obj = i3sDeploymentPlanPage.ID_ELEMENT_DEPLOYMENTPLAN % oedp.name
            ''' In the below code, flags are set/unset based on the validity of the input parameters'''
            if (hasattr(oedp, "newName")):
                if re.search('[^a-zA-Z_]', oedp.newName):
                    special_char_flag = 0
                if (oedp.newName == ""):
                    name_flag = 0
                    special_char_flag = 1
                """ Before Editing check if the Deploymentplan exists by the new name"""
                if s2l._is_element_present(
                        i3sDeploymentPlanPage.ID_ELEMENT_DEPLOYMENTPLAN %
                        oedp.newName):
                    ''' set new_name_flag to 0 if name already exists'''
                    new_name_flag = 0
            s2l.mouse_over(oedp_Obj)
            ui_lib.wait_for_element_and_click(
                i3sDeploymentPlanPage.ID_ELEMENT_DEPLOYMENTPLAN % oedp.name)
            ui_lib.wait_for_element_and_click(
                i3sDeploymentPlanPage.ID_BUTTON_ACTION)
            ui_lib.wait_for_element_and_click(
                i3sDeploymentPlanPage.ID_BUTTON_EDIT)
            ui_lib.wait_for_element(i3sDeploymentPlanPage.ID_EDIT_OEDP_TITLE)

            if (hasattr(oedp, newName_var)):
                if (len(oedp.newName) > MAX_CHAR):
                    new_name_flag = 0
                ui_lib.wait_for_element_and_input_text(
                    i3sDeploymentPlanPage.ID_EDIT_NAME, oedp.newName)
                sleep(5)

            if (hasattr(oedp, desc_var)):
                if (oedp.description == ""):
                    desc_flag = 0
                ui_lib.wait_for_element_and_input_text(
                    i3sDeploymentPlanPage.ID_EDIT_DESCRIPTION,
                    oedp.description)
                sleep(5)

            if (hasattr(oedp, goldenimage_var)):
                if (oedp.goldenimageuri == ""):
                    gi_flag = 0
                if gi_flag:
                    if (oedp.goldenimageuri != 'non-existing-gi'):
                        ui_lib.wait_for_element_and_click(
                            i3sDeploymentPlanPage.ID_EDIT_GOLDENIMAGE_CLOSE)
                        ui_lib.wait_for_element_and_click(
                            i3sDeploymentPlanPage.ID_INPUT_GOLDENIMAGE %
                            oedp.goldenimageuri)
                    else:
                        '''set exis_gi_flag to false if we provide non-existing GI uri'''
                        exis_gi_flag = 0
                        ui_lib.wait_for_element_and_input_text(
                            i3sDeploymentPlanPage.OEDP_EDIT_GI_TEXTBOX,
                            oedp.goldenimageuri)
                else:
                    ui_lib.wait_for_element_and_input_text(
                        i3sDeploymentPlanPage.OEDP_EDIT_GI_TEXTBOX,
                        oedp.goldenimageuri)
                sleep(5)

            if (hasattr(oedp, oebuildplan_var)):
                if (oedp.oebuildplanuri == ""):
                    bp_flag = 0
                if bp_flag:
                    if (oedp.oebuildplanuri != 'non-existing-bp'):
                        ui_lib.wait_for_element_and_click(
                            i3sDeploymentPlanPage.ID_EDIT_BUILDPLAN_CLOSE)
                        ui_lib.wait_for_element_and_click(
                            i3sDeploymentPlanPage.ID_EDIT_BUILDPLAN %
                            oedp.oebuildplanuri)
                    else:
                        '''set exis_bp_flag to false if we provide non-existing BP uri'''
                        exis_bp_flag = 0
                        ui_lib.wait_for_element_and_input_text(
                            i3sDeploymentPlanPage.OEDP_EDIT_BP_TEXTBOX,
                            oedp.oebuildplanuri)
                else:
                    ui_lib.wait_for_element_and_input_text(
                        i3sDeploymentPlanPage.OEDP_EDIT_BP_TEXTBOX,
                        oedp.oebuildplanuri)
                sleep(5)

            if (hasattr(oedp, ostype_var)):
                s2l.select_from_list_by_value(
                    i3sDeploymentPlanPage.ID_EDIT_OSTYPE_LIST, oedp.ostype)

            if (oedp.button != 'cancel'):
                '''Editing an    oedeploymentplan'''
                if (oedp.button == 'edit'):
                    ui_lib.wait_for_element_and_click(
                        i3sDeploymentPlanPage.ID_EDIT_OK_BUTTON)
                    sleep(5)
                    if (hasattr(oedp, goldenimage_var)
                            or hasattr(oedp, oebuildplan_var)):
                        if (gi_flag == 0):
                            if not ui_lib.wait_for_element(
                                    i3sDeploymentPlanPage.
                                    OEDP_BLANK_GI_URL_MESSAGE_EDIT):
                                logger._warn(
                                    "Blank Gi edit error message not found")

                        if hasattr(oedp, oebuildplan_var):
                            if (bp_flag == 0):
                                if not ui_lib.wait_for_element(
                                        i3sDeploymentPlanPage.
                                        OEDP_BLANK_BP_URL_MESSAGE_EDIT):
                                    logger._warn(
                                        "Blank BP edit error message not found"
                                    )
                                    ''' if we have provided non-existing BP uri and non-existing GI uri or just non-existing GI uri and existing BP uri'''
                            elif ((exis_gi_flag == 0 and exis_bp_flag == 1) or
                                  (exis_gi_flag == 0 and exis_bp_flag == 0)):
                                try:
                                    if ui_lib.wait_for_element_visible(
                                            i3sDeploymentPlanPage.ID_ERROR_FORM
                                    ):
                                        text = ui_lib.get_text(
                                            i3sDeploymentPlanPage.ID_ERROR_FORM
                                        )
                                        if len(
                                                ui_lib.get_text(
                                                    i3sDeploymentPlanPage.
                                                    ID_ERROR_FORM).strip()
                                        ) == 0:
                                            logger._warn('no error form found')
                                        elif (text != error_messages.
                                              OEDP_INVALID_GI_URL_EDIT_MESSAGE
                                              ):
                                            logger._warn(
                                                "Error message displayed  doesn't match the invalid golden image error message"
                                            )
                                            logger._log_to_console_and_log_file(
                                                "Error message is" + str(text))
                                except:
                                    logger._warn(
                                        'no invalid golden image error form found'
                                    )
                                ''' if we have provided non-existing BP uri and existing GI uri'''
                            elif (exis_bp_flag == 0 and exis_gi_flag == 1):
                                try:
                                    if ui_lib.wait_for_element_visible(
                                            i3sDeploymentPlanPage.ID_ERROR_FORM
                                    ):
                                        text = ui_lib.get_text(
                                            i3sDeploymentPlanPage.ID_ERROR_FORM
                                        )
                                        if len(
                                                ui_lib.get_text(
                                                    i3sDeploymentPlanPage.
                                                    ID_ERROR_FORM).strip()
                                        ) == 0:
                                            logger._warn('your message')
                                        elif (text != error_messages.
                                              OEDP_INVALID_OEBP_URL_EDIT_MESSAGE
                                              ):
                                            logger._warn(
                                                "Error message displayed  doesn't match the invalid oebuildplan error message"
                                            )
                                            logger._log_to_console_and_log_file(
                                                "Error message is" + str(text))
                                except:
                                    logger._warn(
                                        'no invalid oebuildplan error form found'
                                    )
                            else:
                                ui_lib.wait_for_element_and_click(
                                    i3sDeploymentPlanPage.
                                    ID_ELEMENT_DEPLOYMENTPLAN % oedp.name)
                                if not ui_lib.wait_for_element_visible(
                                        i3sDeploymentPlanPage.
                                        ID_EDIT_BPURI_CHECK %
                                        oedp.oebuildplanuri,
                                        PerfConstants.SUCCESS_TIME):
                                    logger._warn(
                                        "Failed to update with oebuildplan: %s"
                                        % oedp.oebuildplanuri)
                                else:
                                    logger._log_to_console_and_log_file(
                                        "Updated oebuildplan to '%s'" %
                                        oedp.oebuildplanuri)
                        ''' if we have provided non-existing GI uri '''
                        if (exis_gi_flag == 0):
                            try:
                                if ui_lib.wait_for_element_visible(
                                        i3sDeploymentPlanPage.ID_ERROR_FORM):
                                    text = ui_lib.get_text(
                                        i3sDeploymentPlanPage.ID_ERROR_FORM)
                                    if len(
                                            ui_lib.get_text(
                                                i3sDeploymentPlanPage.
                                                ID_ERROR_FORM).strip()) == 0:
                                        logger._warn('no error form found')
                                    elif (text != error_messages.
                                          OEDP_INVALID_GI_URL_EDIT_MESSAGE):
                                        logger._warn(
                                            "Error message displayed  doesn't match the invalid golden image error message"
                                        )
                            except:
                                logger._warn(
                                    'invalid golden image error form found')

                    if hasattr(oedp, goldenimage_var):
                        ''' if we have provided valid GI uri '''
                        if (gi_flag == 1 and exis_gi_flag == 1):
                            ''' Checking if goldenimageuri is updated'''
                            ui_lib.wait_for_element_and_click(
                                i3sDeploymentPlanPage.ID_ELEMENT_DEPLOYMENTPLAN
                                % oedp.name)
                            if not ui_lib.wait_for_element_visible(
                                    i3sDeploymentPlanPage.ID_EDIT_GIURI_CHECK %
                                    oedp.goldenimageuri,
                                    PerfConstants.SUCCESS_TIME):
                                logger._warn(
                                    "Failed to update with goldenimage: %s" %
                                    oedp.goldenimageuri)
                            else:
                                logger._log_to_console_and_log_file(
                                    "Updated goldenimage to '%s'" %
                                    oedp.goldenimageuri)

                    if hasattr(oedp, ostype_var):
                        ''' Checking if ostype is updated'''
                        ui_lib.wait_for_element_and_click(
                            i3sDeploymentPlanPage.ID_ELEMENT_DEPLOYMENTPLAN %
                            oedp.name)
                        if not ui_lib.wait_for_element_visible(
                                i3sDeploymentPlanPage.ID_EDIT_OSTYPE_CHECK %
                                oedp.ostype, PerfConstants.SUCCESS_TIME):
                            logger._warn("Failed to update with ostype: %s" %
                                         oedp.ostype)
                        else:
                            logger._log_to_console_and_log_file(
                                "Updated ostype to '%s'" % oedp.ostype)

                    if hasattr(oedp, newName_var):
                        if (name_flag == 0):
                            ''' If goldenimage name is NULL then throw error and continue to the next test scenario'''
                            if not ui_lib.wait_for_element(
                                    i3sDeploymentPlanPage.ID_BLANK_NAME):
                                logger._warn(
                                    "Blank name error message not found")
                            else:
                                logger._log_to_console_and_log_file(
                                    "blank name error message found")
                        else:
                            if (special_char_flag == 1 and new_name_flag == 1):
                                if not ui_lib.wait_for_element_visible(
                                        i3sDeploymentPlanPage.
                                        ID_ELEMENT_DEPLOYMENTPLAN %
                                        oedp.newName,
                                        PerfConstants.SUCCESS_TIME):
                                    logger._warn(
                                        "Failed to update with newName: %s" %
                                        oedp.newName)
                                else:
                                    logger._log_to_console_and_log_file(
                                        "Updated Name to '%s'" % oedp.newName)
                        if (new_name_flag == 0):
                            try:
                                if ui_lib.wait_for_element_visible(
                                        i3sDeploymentPlanPage.ID_ERROR_FORM):
                                    text = ui_lib.get_text(
                                        i3sDeploymentPlanPage.ID_ERROR_FORM)
                                    text1 = text.strip()
                                    logger._log_to_console_and_log_file(
                                        "text1 is" + str(text1))
                                    if len(
                                            ui_lib.get_text(
                                                i3sDeploymentPlanPage.
                                                ID_ERROR_FORM).strip()) == 0:
                                        logger._warn(
                                            'Duplicate name error form found')
                                    elif (text1 != error_messages.
                                          OEDP_DUPLICATE_NAME_EDIT_MESSAGE):
                                        logger._warn(
                                            "Duplicate name edit error message is not displayed"
                                        )
                                        logger._log_to_console(
                                            "Error message is" + str(text))
                                else:
                                    logger._warn('No error form found')
                            except:
                                logger._warn('no error form found')
                        if (special_char_flag == 0):
                            try:
                                if ui_lib.wait_for_element_visible(
                                        i3sDeploymentPlanPage.ID_ERROR_FORM):
                                    text = ui_lib.get_text(
                                        i3sDeploymentPlanPage.ID_ERROR_FORM)
                                    if len(
                                            ui_lib.get_text(
                                                i3sDeploymentPlanPage.
                                                ID_ERROR_FORM).strip()) == 0:
                                        logger._warn('no error form found')
                                    elif (text != error_messages.
                                          OEDP_INVALID_INPUT_EDIT_MESSAGE):
                                        logger._warn(
                                            "invalid name error message is not displayed"
                                        )
                                        logger._log_to_console_and_log_file(
                                            "Error message is" + str(text))
                            except:
                                logger._warn('invalid name error form found')

                    if hasattr(oedp, desc_var):
                        if (desc_flag == 0):
                            if not ui_lib.wait_for_element(
                                    i3sDeploymentPlanPage.
                                    ID_BLANK_DESCRIPTION_EDIT):
                                logger._warn(
                                    "Blank descriptionedit error message not found"
                                )
                        else:
                            ''' Checking if description is updated'''
                            ui_lib.wait_for_element_and_click(
                                i3sDeploymentPlanPage.ID_ELEMENT_DEPLOYMENTPLAN
                                % oedp.name)
                            if not ui_lib.wait_for_element(
                                    i3sDeploymentPlanPage.ID_EDIT_DESC_CHECK %
                                    oedp.description):
                                logger._warn(
                                    "Failed to update oedp %s description: %s"
                                    % (oedp.name, oedp.description))
                            else:
                                logger._log_to_console_and_log_file(
                                    "Updated Description to '%s'" %
                                    oedp.description)

            elif (oedp.button == 'cancel'):
                '''Cancelling an oedeploymentplan edit operation'''
                ui_lib.wait_for_element_and_click(
                    i3sDeploymentPlanPage.ID_EDIT_CANCEL_BUTTON)
                if ui_lib.wait_for_element_visible(
                        i3sDeploymentPlanPage.ID_CANCEL_CONFIRM_FORM):
                    ui_lib.wait_for_element_and_click(
                        i3sDeploymentPlanPage.ID_CANCEL_PROCEED_BUTTON)
                if ui_lib.wait_for_element_visible(
                        i3sDeploymentPlanPage.ID_PAGE_LABEL):
                    logger._log_to_console_and_log_file(
                        "returned successfully to OEDP UI")
                else:
                    logger._warn(
                        "Failed to return to OEDP UI post clicking cancel in Edit OEDP UI"
                    )
                continue
            '''Returning to OEDP UI after successful/failed edit operation'''
            if ui_lib.wait_for_element_visible(
                    i3sDeploymentPlanPage.ID_EDIT_OEDP_TITLE):
                ui_lib.wait_for_element_and_click(
                    i3sDeploymentPlanPage.ID_EDIT_CANCEL_BUTTON)
                if ui_lib.wait_for_element_visible(
                        i3sDeploymentPlanPage.ID_CANCEL_CONFIRM_FORM):
                    ui_lib.wait_for_element_and_click(
                        i3sDeploymentPlanPage.ID_CANCEL_PROCEED_BUTTON)
            elif ui_lib.wait_for_element_visible(
                    i3sDeploymentPlanPage.ID_PAGE_LABEL):

                logger._log_to_console_and_log_file(
                    "returned successfully to OEDP UI")
            else:
                logger._warn(
                    "Failed to return to OEDP UI post clicking cancel in Edit OEDP UI"
                )
                continue
        else:
            logger._warn(
                "Failed to edit the deployment plan as the name provided does not exist on the OEDP UI page"
            )
            continue
    return
def login(user_name):
    s2l = ui_lib.get_s2l()
    logger._log_to_console('Login status = {0}'.format(
        str(FusionUIBase.logged_in())))

    if FusionUIBase.logged_in():
        base_page.logout()

    user = test_data.get_user_by_name(user_name)

    # check the existing login status
    logger._log_to_console_and_log_file(
        "Logging into Fusion as {0}/{1}".format(user.name, user.password))
    if s2l._is_element_present(FusionLoginPage.ID_BTN_EULA_AGREE):
        s2l.click_button(FusionLoginPage.ID_BTN_EULA_AGREE)

    s2l.wait_until_page_contains_element(FusionLoginPage.ID_BTN_LOGIN_BUTTON)
    s2l.input_text(FusionLoginPage.ID_INPUT_LOGIN_USER, user.name)
    s2l.input_text(FusionLoginPage.ID_INPUT_LOGIN_PASSWORD, user.password)

    # code to login as  active directory user
    if (user.has_property("domainName")):
        s2l.click_element(FusionLoginPage.ID_ELEMENT_AUTHN_PROVIDER)
        dirListObj = FusionLoginPage.ID_ELEMENT_DIR % user.domainName.strip()

        s2l.click_element(dirListObj)
        activedir = s2l.get_text(FusionLoginPage.ID_COMBO_AUTHN_PROVIDER)
        if not activedir == user.domainName.strip():
            logger._warn(
                "Not able to login to the appliance with active directory users .."
            )
            ui_lib.fail_test(
                "not able to login as active directory users... verify AD users and groups is added to the appliance"
            )

    s2l.click_button(FusionLoginPage.ID_BTN_LOGIN_BUTTON)

    # Close Oneview Tutorial Dialog Box if Exits
    if ui_lib.wait_for_element_visible(
            FusionLoginPage.ID_ONEVIEW_TUTORIAL_DIALOG, 15):
        s2l.click_element(FusionLoginPage.ID_ONEVIEW_TUTORIAL_CLOSE)
        logger.info("OneView Tutorial Dialog existed and is now closed")

    # These elements may not exist if the login page is transitioning to the dashboard
    # page.  In order to avoid failing conditions, we will catch any exceptions
    try:
        s2l.element_should_not_be_visible(FusionLoginPage.ID_ALL_ERROR_FIELDS)
        s2l.element_text_should_be(FusionLoginPage.ID_LABEL_LOGIN_STATUS, "")
    except:
        pass

    if s2l._is_element_present(FusionLoginPage.ID_BTN_EULA_AGREE):
        s2l.click_button(FusionLoginPage.ID_BTN_EULA_AGREE)
    if s2l._is_element_present(FusionLoginPage.ID_BTN_EULA_OK):
        s2l.click_button(FusionLoginPage.ID_BTN_EULA_OK)

    if s2l._is_element_present(FusionLoginPage.ID_INPUT_APPLIANCE_HOSTNAME):
        s2l.click_element(FusionLoginPage.ID_RADIO_IPV4_DHCP)
        s2l.click_button(FusionLoginPage.ID_APPLIANCE_OK)
        # wait up to 2 mins for applying settings screen to disappear
        ui_lib.wait_for_element_notvisible(
            FusionLoginPage.ID_APPLIANCE_APPLYING_SETTINGS, 150,
            "Applying Setting screen did not disappear")

    s2l.wait_until_page_contains_element(FusionDashboardPage.ID_PAGE_LABEL,
                                         PerfConstants.FUSION_LOGIN_TIME,
                                         "Failed to load the Login Page")
    FusionUIBase.set_login_status(True)

    # hide the guided setup panel
    base_page.close_guided_setup_panel()
    return True