Actions.CommonActions package

Submodules

Actions.CommonActions.common_actions module

Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

class Actions.CommonActions.common_actions.CommonActions[source]

Bases: object

class CommonActions having methods (keywords) that are common for all the products

get_current_timestamp(current_time='current_time')[source]

Returns system current timestamp. :Arguments:

  1. current_time (string) : name of the key to store in data repository
Returns:
  1. status(boolean)

  2. current_time (dict element) : name = current_time given in the argument,

    value = Current System Time in the object format of Year, Month, Date, Time(without microseconds)

    Ex :datetime.datetime(2018, 10, 22, 5, 51, 21)

get_system_type(system_name)[source]

Finds the system name in the datafile and returns the system type :Arguments:

  1. system_name = system name in the datafile
Returns:
  1. status (boolean)
  2. system_type (dict element): name=system_type, value=type of the system_name (string).
get_time_delta(start_time, end_time=None, time_diff='time_diff')[source]

Returns time difference between two timestamps in seconds. :Arguments:

  1. start_time = start time key in the data repository,
    value should be datetime object in data repo. Ex: ‘timestamp1’
  2. end_time(optional) = end time key in the data repository,
    value should be datetime object in data repo. Ex: ‘timestamp2’
  1. time_diff(optional) = time diff key in the data repository
Returns:
  1. status(boolean)
  2. time_diff (dict element) : name = time_diff, value = difference between the given start time and end time in seconds (ex: 212342.0)
set_env_var(var_key=None, var_value=None, filepath=None, jsonkey='environmental_variables', overwrite='yes')[source]

Create a temp environment variable, the value will only stay for the current Execution :Argument:

var_key = key of the environment variable var_value = value of the environment variable filepath = Json file where Environmental variables are defined jsonkey = The key where all the ENV variable & values are defined
With jsonkey arg, Users can call same file to set various ENV Variable
overwrite = Yes-Will overwrite ENV variables set earlier via terminal or other means
No -Will not overwrite the ENV variables set earlier with the ones passed
through this keyword.

Variable File : Sample environmental_variable file is available under Warriorspace/Config_file/Samples/Set_ENV_Variable_Sample.json

store_in_repo(datavar=None, datavalue=None, type='str', filepath=None, jsonkey='repo_variables')[source]

Stores datavalue in datavar of datarepository :Argument:

  1. datavar = Key to be used to store datavalue in data_repository,
    this could be dot separated to store in nested fashion
    i.e., if var is k1.k2.k3 then the data value would be stored as a value in datarepository[k1][k2][k3]
  2. datavalue = Value to be stored
  3. type = Type of datavalue(string/int/float)
  4. filepath = Json file where datarepository variables are defined.
    It is to store multiple key,value pairs in datarepository.
  5. jsonkey = The key where all the REPO variables & values are
    defined in the filepath
Sample JSON file:
{
“repo_variables”: {
“var1”: {“type”: “int”, “value”: “10”}, “var2.var3”: {“value”: “10”}, “var4.var5”: “1” },
“user_defined_tag”:{
“var6” : {“type”: “int”, “value”: “40”} }

}

All three formats in the above sample block are allowed. If ‘type’ is not provided, value will be converted as string by default.

verify_arith_exp(expression, expected, comparison='eq', repo_key='exp_op')[source]

Verify the output of the arithmetic expression matches the expected(float comparison) Note : Binary floating-point arithmetic holds many surprises. Please refer to link, https://docs.python.org/2/tutorial/floatingpoint.html This Keyword inherits errors in Python float operations. :Arguments:

  1. expression: Arithmetic expression to be compared with expected.
    This can have env & data_repo values embedded in it.

    Ex. expression: “10+${ENV.x}-${REPO.y}*10”

    Expression will be evaluated based on python operator precedence

  2. expected: Value to be compared with the expression output

    This can be a env or data_repo or any numeral value.

  3. comparison: Type of comparison(eq/ne/gt/ge/lt/le)

    eq - check if both are same(equal) ne - check if both are not same(not equal) gt - check if expression output is greater than expected ge - check if expression output is greater than or equal to expected lt - check if expression output is lesser than expected le - check if expression output is lesser than or equal to expected

  4. repo_key: Name of the key to be used to save the expression_output in the warrior data repository

    Ex. If repo_key is ‘exp_op’ & expression_output is 10.0

    It will be stored in data_repo in the below format data_repo = {

    … verify_arith_exp: {‘exp_op’: 10.0}, …

    }

    This value can be retrieved from data_repo using key : ‘verify_arith_exp.exp_op’.

Returns:
  1. status(boolean)
verify_data(expected, object_key, type='str', comparison='eq')[source]

Verify value in ‘object_key’ in the data repository matches with expected :Argument:

expected = the value to be compared with object_key = the object in the data repository to be compared type = the type of this expected (str/int/float) comparison = actual comparison (eq/ne/gt/ge/lt/le)

eq - check if both are same(equal) ne - check if both are not same(not equal) gt - check if object_key is greater than expected ge - check if object_key is greater than or equal to expected lt - check if object_key is lesser than expected le - check if object_key is lesser than or equal to expected
Returns:status (boolean)
verify_resp_data(resp_ref, resp_pat, object_key)[source]

Verify ‘resp_pat’ exist in the data repository :Argument:

resp_ref = response reference tag in testdatafile resp_pat = response pattern to be check in testdatafile object_key = the object key name in the data repository

Ex: cli send by title, object_key=<title name>
cli send by tiele_rownum, object key=<tilte_name><row_name>
Returns:status (boolean)
wait_for_timeout(timeout, notify_count=4)[source]

waits (sleeps) for the time provided

Arguments:
  1. timeout= time to wait in seconds
  2. notify_count= number of times, the user needs to be notified
    during wait time. Default value is 4. Ex: If the notify_count=4 and timeout=400 the timeout is divided into 4 partitions each as 100 and notified to user as 100(25%),200(50%),300(75%),400(100%)
Returns:
  1. status (bool)

Module contents

Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.