Basic Tests for DAEXIM project 02/48602/13
authorsdevaraj <kalyan.ds@gmail.com>
Wed, 23 Nov 2016 02:21:34 +0000 (18:21 -0800)
committersdevaraj <kalyan.ds@gmail.com>
Wed, 30 Nov 2016 19:52:16 +0000 (11:52 -0800)
  - Replace tabs with spaces
  - Fixing Utils keyword for rc
  - Fixing the style errors
  - Fix for a failure in the jenkins
  - Removing the test suites which are not ready
  - Adding json files for export and import
  - First commit for branch testing
  - Fixed the first set of comments on review
  - Removed reference to ODL_SYSTEM_IP and added cluster_index for better portability to cluster test cases
  - Fixed tidytool issues

Change-Id: Ia0de7bbb2a08f9411715dd64b4fe42e140702ae2
Signed-off-by: sdevaraj <kalyan.ds@gmail.com>
csit/libraries/ClusterManagement.robot
csit/libraries/DaeximKeywords.robot [new file with mode: 0644]
csit/libraries/Utils.robot
csit/suites/daexim/010-special-export.robot [new file with mode: 0644]
csit/testplans/daexim-basic.txt [new file with mode: 0644]
csit/variables/daexim/DaeximVariables.robot [new file with mode: 0644]
csit/variables/daexim/schedule_backup.json [new file with mode: 0644]
csit/variables/daexim/schedule_backup_exclude.json [new file with mode: 0644]

index d1be3e583d256230bbaac1b2fa19592532e3a07a..4b8b5974c5ab7e6e20e39ba5bb54d6daca5415fd 100644 (file)
@@ -427,8 +427,8 @@ Run_Bash_Command_On_Member
     [Documentation]    Obtain IP, call Utils and return output. This does not preserve active ssh session.
     # TODO: Rename these keyword to Run_Bash_Command_On_Member to distinguish from Karaf (or even Windows) commands.
     ${member_ip} =    Collections.Get_From_Dictionary    dictionary=${ClusterManagement__index_to_ip_mapping}    key=${member_index}
-    ${output} =    SSHKeywords.Run_Keyword_Preserve_Connection    Utils.Run_Command_On_Controller    ${member_ip}    ${command}
-    [Return]    ${output}
+    ${output}    ${rc} =    SSHKeywords.Run_Keyword_Preserve_Connection    Utils.Run_Command_On_Controller    ${member_ip}    ${command}
+    [Return]    ${output}    ${rc}
 
 Run_Karaf_Command_On_List_Or_All
     [Arguments]    ${command}    ${member_index_list}=${EMPTY}    ${timeout}=10s
diff --git a/csit/libraries/DaeximKeywords.robot b/csit/libraries/DaeximKeywords.robot
new file mode 100644 (file)
index 0000000..2df02cf
--- /dev/null
@@ -0,0 +1,126 @@
+*** Settings ***
+Library           OperatingSystem
+Library           SSHLibrary
+Resource          ClusterManagement.robot
+Resource          ../variables/Variables.robot
+Resource          ../variables/daexim/DaeximVariables.robot
+Variables         ../variables/Variables.py
+Resource          ../variables/Variables.robot
+Resource          Utils.robot
+
+*** Keywords ***
+Verify Backup Files
+    [Arguments]    ${host_index}
+    [Documentation]    Verify if the backedup files are present in the controller
+    ${host_index}    Builtin.Convert To Integer    ${host_index}
+    ${cfg}    ${rc}    ClusterManagement.Run Bash Command On Member    ls -lart ${WORKSPACE}/${BUNDLEFOLDER}/daexim/${BKP_DATA_FILE}    ${host_index}
+    Builtin.Run Keyword If    "${rc}" != "0"    Builtin.Fail    Return code is not equal to zero on this command
+    ...    ELSE    Builtin.Log    ${cfg}
+    ${mdl}    ${rc}    ClusterManagement.Run Bash Command On Member    ls -lart ${WORKSPACE}/${BUNDLEFOLDER}/daexim/${MODELS_FILE}    ${host_index}
+    Builtin.Run Keyword If    "${rc}" != "0"    Builtin.Fail    Return code is not equal to zero on this command
+    ...    ELSE    Builtin.Log    ${mdl}
+    ${opr}    ${rc}    ClusterManagement.Run Bash Command On Member    ls -lart ${WORKSPACE}/${BUNDLEFOLDER}/daexim/${BKP_OPER_FILE}    ${host_index}
+    Builtin.Run Keyword If    "${rc}" != "0"    Builtin.Fail    Return code is not equal to zero on this command
+    ...    ELSE    Builtin.Log    ${opr}
+
+Cleanup The Backup Files
+    [Arguments]    ${host_index}
+    [Documentation]    Verify if the backup directory exists and delete the files if needed
+    ${host_index}    Builtin.Convert To Integer    ${host_index}
+    ${output}    ${rc}    ClusterManagement.Run Bash Command On Member    sudo rm -rf ${WORKSPACE}/${BUNDLEFOLDER}/daexim    ${host_index}
+    Builtin.Run Keyword If    "${rc}" != "0"    Fail    Return code is not equal to zero on this command
+    ...    ELSE    Builtin.Log    ${output}
+
+Verify Backup Status
+    [Arguments]    ${status}    ${controller_index}
+    [Documentation]    Verify backup status is as expected
+    ${response_json}    ClusterManagement.Post As Json To Member    ${STATUS_BACKUP_URL}    ${EMPTY}    ${controller_index}
+    Builtin.Log    ${response_json}
+    ${response_json}    Builtin.Convert To String    ${response_json}
+    Verify Backup Status Message    ${status}    ${response_json}
+
+Verify Scheduled Backup Timestamp
+    [Arguments]    ${controller_index}    ${time}
+    [Documentation]    Verify backup timestamp is as expected
+    ${response_json}    ClusterManagement.Post As Json To Member    ${STATUS_BACKUP_URL}    ${EMPTY}    ${controller_index}
+    Builtin.Log    ${response_json}
+    ${response_json}    Builtin.Convert To String    ${response_json}
+    Builtin.Should Match Regexp    ${response_json}    .*"run-at": "${time}"
+
+Verify Backup Status Message
+    [Arguments]    ${status}    ${output}
+    [Documentation]    Verify backup restconf response message is as expected
+    Builtin.Should Match Regexp    ${output}    "status": "${status}"
+    Builtin.Run Keyword If    "${status}" == "initial" or "${status}" == "scheduled"    Verify Json Files Not Present    ${output}
+    ...    ELSE    Verify Json Files Present    ${output}
+
+Verify Json Files Present
+    [Arguments]    ${output}    ${config_json}=${BKP_DATA_FILE}    ${models_json}=${MODELS_FILE}    ${operational_json}=${BKP_OPER_FILE}
+    [Documentation]    Verify if the json files are generated after a backup/export
+    Builtin.Should Match Regexp    ${output}    .*${config_json}
+    Builtin.Should Match Regexp    ${output}    .*${models_json}
+    Builtin.Should Match Regexp    ${output}    .*${operational_json}
+    Builtin.Log    Found all Json Files
+
+Verify Json Files Not Present
+    [Arguments]    ${output}    ${config_json}=${BKP_DATA_FILE}    ${models_json}=${MODELS_FILE}    ${operational_json}=${BKP_OPER_FILE}
+    [Documentation]    Verify if the json files are not present under the daexim folder
+    Builtin.Should Not Match Regexp    ${output}    .*${config_json}
+    Builtin.Should Not Match Regexp    ${output}    .*${models_json}
+    Builtin.Should Not Match Regexp    ${output}    .*${operational_json}
+    Builtin.Log    Did not Find all Json Files
+
+Schedule Backup
+    [Arguments]    ${controller_index}    ${TIME}=500    ${exclude}=${FALSE}    ${MODULE}=${EMPTY}    ${STORE}=${EMPTY}
+    ${file}    Builtin.Set Variable If    ${exclude}    ${BACKUP_EXCLUDE_FILE}    ${BACKUP_FILE}
+    ${JSON1}    OperatingSystem.Get File    ${file}
+    ${JSON2}    Builtin.Replace Variables    ${JSON1}
+    Cleanup The Backup Files    ${controller_index}
+    ${response_json}    ClusterManagement.Post As Json To Member    ${SCHEDULE_BACKUP_URL}    ${JSON2}    ${controller_index}
+
+Schedule Exclude Backup
+    [Arguments]    ${controller_index}    ${store}    ${module}
+    [Documentation]    Schedules a backup with exclude option. Returns the file that has the excluded backup.
+    ${controller_index}    Builtin.Convert To Integer    ${controller_index}
+    ${host}    ClusterManagement.Resolve IP Address For Member    ${controller_index}
+    Schedule Backup    ${controller_index}    500    ${TRUE}    ${module}    ${store}
+    Builtin.Wait Until Keyword Succeeds    10 sec    5 sec    Verify Backup Status    complete    ${controller_index}
+    Verify Backup Files    ${controller_index}
+    Copy Backup Directory To Test VM    ${host}
+    ${backup_file}    Builtin.Set Variable If    '${store}' == 'operational'    ${BKP_OPER_FILE}    ${BKP_DATA_FILE}
+    ${file_path}    OperatingSystem.Join Path    ${BKP_DIR}${host}    ${backup_file}
+    [Return]    ${file_path}
+
+Cancel Backup
+    [Arguments]    ${controller_index}
+    [Documentation]    Cancel the export job
+    ClusterManagement.Post As Json To Member    ${CANCEL_BACKUP_URL}    ${EMPTY}    ${controller_index}
+
+Return ConnnectionID
+    [Arguments]    ${system}=${ODL_SYSTEM_IP}    ${prompt}=${DEFAULT_LINUX_PROMPT}    ${prompt_timeout}=${DEFAULT_TIMEOUT}    ${user}=${ODL_SYSTEM_USER}    ${password}=${ODL_SYSTEM_PASSWORD}
+    [Documentation]    Returns the connection of any host. Defaults to controller
+    ${conn_id}    SSHLibrary.Open Connection    ${system}    prompt=${prompt}    timeout=${prompt_timeout}
+    Utils.Flexible SSH Login    ${user}    ${password}
+    [Return]    ${conn_id}
+
+Cleanup Directory
+    [Arguments]    ${dir}
+    [Documentation]    Cleans up the given directory if it exists
+    OperatingSystem.Empty Directory    ${dir}
+    OperatingSystem.Remove Directory    ${dir}
+
+Copy Backup Directory To Test VM
+    [Arguments]    ${host}
+    [Documentation]    This keyword copies the daexim folder genereated in the controller to robot vm. This is done to editing if needed on the json files
+    ${new_dir}    Builtin.Set Variable    ${BKP_DIR}${host}
+    ${directory_exist}    Builtin.Run Keyword And Return Status    OperatingSystem.Directory Should Exist    ${new_dir}
+    Builtin.Run Keyword If    ${directory_exist}    Cleanup Directory    ${new_dir}
+    ${connections}    Return ConnnectionID    ${host}
+    SSHLibrary.Switch Connection    ${connections}
+    SSHLibrary.Directory Should Exist    ${WORKSPACE}/${BUNDLEFOLDER}/daexim
+    SSHLibrary.Get Directory    ${WORKSPACE}/${BUNDLEFOLDER}/daexim    ${new_dir}
+    SSHLibrary.Close Connection
+    ${output}    OperatingSystem.List Files In Directory    ${new_dir}
+    Builtin.Log    ${output}
+    ${fl}    OperatingSystem.Get File    ${new_dir}/${BKP_DATA_FILE}
+    Builtin.Log    ${fl}
index 1d918f92b296c9363cc7845ddf43092e968e9c84..d700bd7ee9a0974d22c355584b3b496ab6e9527a 100644 (file)
@@ -196,11 +196,11 @@ Run Command On Remote System
     BuiltIn.Log    ${password}
     ${conn_id}=    SSHLibrary.Open Connection    ${system}    prompt=${prompt}    timeout=${prompt_timeout}
     Flexible SSH Login    ${user}    ${password}
-    ${stdout}    ${stderr}    SSHLibrary.Execute Command    ${cmd}    return_stderr=True
+    ${stdout}    ${stderr}    ${rc}    SSHLibrary.Execute Command    ${cmd}    return_stderr=True    return_rc=True
     SSHLibrary.Close Connection
     Log    ${stderr}
     [Teardown]    SSHKeywords.Restore_Current_SSH_Connection_From_Index    ${current_ssh_connection.index}
-    [Return]    ${stdout}
+    [Return]    ${stdout}    ${rc}
 
 Write_Bare_Ctrl_C
     [Documentation]    Construct ctrl+c character and SSH-write it (without endline) to the current SSH connection.
diff --git a/csit/suites/daexim/010-special-export.robot b/csit/suites/daexim/010-special-export.robot
new file mode 100644 (file)
index 0000000..de90ab8
--- /dev/null
@@ -0,0 +1,58 @@
+*** Settings ***
+Documentation     Test suite for backing up data and models
+Suite Setup       ClusterManagement Setup
+Suite Teardown    Delete All Sessions
+Library           OperatingSystem
+Library           DateTime
+Resource          ../../libraries/DaeximKeywords.robot
+
+*** Test Cases ***
+Create and Cancel Backup
+    [Documentation]    schedule and cancel backup of a cluster
+    [Tags]    cancel backup
+    DaeximKeywords.Verify Backup Status    initial    1
+    DaeximKeywords.Schedule Backup    1
+    DaeximKeywords.Verify Backup Status    scheduled    1
+    DaeximKeywords.Cancel Backup    1
+    DaeximKeywords.Verify Backup Status    initial    1
+
+Schedule Absolute Time Backup With UTC
+    [Documentation]    Schedule backup at a particular time
+    [Tags]    absolute time backup
+    ${time}    DateTime.Get Current Date    UTC    00:00:10    %Y-%m-%dT%H:%M:%SZ    ${FALSE}
+    DaeximKeywords.Schedule Backup    1    ${time}
+    BuiltIn.Wait Until Keyword Succeeds    20 sec    5 sec    DaeximKeywords.Verify Scheduled Backup Timestamp    1    ${time}
+    Builtin.Wait Until Keyword Succeeds    20 sec    5 sec    DaeximKeywords.Verify Backup Status    complete    1
+    DaeximKeywords.Verify Backup Files    1
+
+Schedule Absolute Time Backup With Localtime
+    [Documentation]    Schedule backup at a particular time
+    [Tags]    absolute time backup
+    ${time}    DateTime.Get Current Date    local    00:00:10    %Y-%m-%dT%H:%M:%S+000    ${FALSE}
+    Builtin.Run Keyword And Expect Error    *    Schedule Backup    1    ${time}
+
+Schedule Absolute Time Backup In Past
+    [Documentation]    Schedule backup at a particular time
+    [Tags]    absolute time backup
+    ${time}    DateTime.Get Current Date    UTC    -00:00:10    %Y-%m-%dT%H:%M:%SZ    ${FALSE}
+    Builtin.Run Keyword And Expect Error    *    Schedule Backup    1    ${time}
+
+Create Module Exclude Backup
+    [Documentation]    schedule backup with exclude option on a cluster
+    [Tags]    exclude backup
+    ${file1}    DaeximKeywords.Schedule Exclude Backup    1    config    network-topology
+    ${lines1}    OperatingSystem.Grep File    ${file1}    network-topology:
+    Builtin.Should Be Empty    ${lines1}
+    ${file2}    DaeximKeywords.Schedule Exclude Backup    1    operational    opendaylight-inventory
+    ${lines2}    OperatingSystem.Grep File    ${file2}    opendaylight-inventory:
+    Builtin.Should Be Empty    ${lines2}
+
+Create Wildcard Exclude Backup
+    [Documentation]    schedule backup with wildstar exclude option
+    [Tags]    wildcard exclude backup
+    ${file1}    DaeximKeywords.Schedule Exclude Backup    1    config    *
+    ${lines1}    Operating System.Get File    ${file1}
+    Builtin.Should Be Equal    ${lines1}    {}
+    ${file2}    Schedule Exclude Backup    1    operational    *
+    ${lines2}    Operating System.Get File    ${file2}
+    Builtin.Should Be Equal    ${lines2}    {}
diff --git a/csit/testplans/daexim-basic.txt b/csit/testplans/daexim-basic.txt
new file mode 100644 (file)
index 0000000..0698923
--- /dev/null
@@ -0,0 +1 @@
+test/csit/suites/daexim/010-special-export.robot
diff --git a/csit/variables/daexim/DaeximVariables.robot b/csit/variables/daexim/DaeximVariables.robot
new file mode 100644 (file)
index 0000000..484e746
--- /dev/null
@@ -0,0 +1,13 @@
+*** Settings ***
+Documentation     Resource consisting purely of variable definitions useful for multiple project suites.
+
+*** Variables ***
+${CANCEL_BACKUP_URL}    /restconf/operations/data-export-import:cancel-export
+${BACKUP_FILE}    ${CURDIR}/schedule_backup.json
+${BKP_DIR}        /tmp/Backup
+${BACKUP_EXCLUDE_FILE}    ${CURDIR}/schedule_backup_exclude.json
+${SCHEDULE_BACKUP_URL}    /restconf/operations/data-export-import:schedule-export
+${BKP_DATA_FILE}    odl_backup_config.json
+${BKP_OPER_FILE}    odl_backup_operational.json
+${MODELS_FILE}    odl_backup_models.json
+${STATUS_BACKUP_URL}    /restconf/operations/data-export-import:status-export
diff --git a/csit/variables/daexim/schedule_backup.json b/csit/variables/daexim/schedule_backup.json
new file mode 100644 (file)
index 0000000..fbdc553
--- /dev/null
@@ -0,0 +1,5 @@
+ {
+   "input": {
+    "data-export-import:run-at": "${TIME}"
+   }
+ }
diff --git a/csit/variables/daexim/schedule_backup_exclude.json b/csit/variables/daexim/schedule_backup_exclude.json
new file mode 100644 (file)
index 0000000..173cf55
--- /dev/null
@@ -0,0 +1,11 @@
+ {
+     "input": {
+         "data-export-import:run-at": ${TIME},
+         "data-export-import:excluded-modules" : [
+             {
+                 "module-name": "${MODULE}",
+                 "data-store": "${STORE}"
+             }
+         ]
+     }
+ }