diff --git a/cdk-testsuite/README.md b/cdk-testsuite/README.md index e69de29..ac4e7eb 100644 --- a/cdk-testsuite/README.md +++ b/cdk-testsuite/README.md @@ -0,0 +1,61 @@ + +# Project :: Automation CDK(container Developement Kit) + +This automation project it based on Avocado framework , Python 2.7 .It has ability to run on Mac OSX ,Windows , Fedora, CentOS and REHL + +Few pre-requesites to run this project on your test machine + +Install pexpect lib on your system (easy_install pexpect or pip install pexpect) + + + + +# How to run this project on Windows Machine + + +Install (tested in cygwin) + + For this you need to download the apt-cyg lib and paste this lib into your cygwin/bin( apt-cyg install python-setuptools python-yaml python-test) + + easy_install-2.7 pip + + pip install stevedore + + download and unpack sources from https://github.com/avocado-framework/avocado/releases + + python setup.py install + + + +# How to run this project on Mac Machine + + + +- root user enabled (by default is disabled) + - System Integrity Protection (SIP aka rootless) feature enabled (default since El Captain) + +So there are multiple ways how to use python on Mac, with SIP in El Captain +things get more complicated. But we do not want to require SIP disabled of course. +For a lot of details see eg.: +http://apple.stackexchange.com/questions/209572/how-to-use-pip-after-the-el-capitan-max-os-x-upgrade + + +first try with system installed python 2.7.10 + +$ mkdir avocado +$ cd avocado +$ git clone https://github.com/avocado-framework/avocado +$ cd avocado + + sudo -H easy_install pip # probably not needed, next step should do it + sudo make requirements + + -> need to comment these in requirements.txt + - libvirt-python + - pyliblzma + -> need different six version then system installed + - could be workaround, but I decided to try other ways first + + + +/*RHEL ,CENTOS and fedora explaination pending*/ diff --git a/cdk-testsuite/config/config.yaml b/cdk-testsuite/config/config.yaml new file mode 100644 index 0000000..66db4b4 --- /dev/null +++ b/cdk-testsuite/config/config.yaml @@ -0,0 +1,14 @@ +Linux: '/home/naina/Documents/cdk/components/rhel/' +Mac : '' +CYGWIN_NT-10.0 : '/cygdrive/c/Users/naina/Downloads/TestingBuilds/rc5/cdk/components/rhel/' +#CYGWIN_NT-10.0 : '/cygdrive/c/Users/naina/Downloads/TestingBuilds/rc5/cdk/components/rhel/' +vagrant_RHN_USERNAME: 'naverma@redhat.com' +vagrant_RHN_PASSWORD: '******************' +vagrant_PLUGINS_DIR: 'C:/Users/naina/Downloads/TestingBuilds/rc5/cdk/plugins/' +vagrant_VARGRANTFILE_DIRS: 'C:/Users/naina/Downloads/TestingBuilds/rc5/cdk/components/rhel/' +vagrant_BOX_PATH: 'C:/Users/naina/Downloads/TestingBuilds/rc5/rhel-cdk-kubernetes-7.2-26.x86_64.vagrant-hyperv.box' +SudoPassword: 'm0m' +Latest_build_link: 'http://cdk-builds.usersys.redhat.com/builds/nightly/latest-build/' +vagrant_PROVIDER: 'hyperv' +Windows_Shell : 'cmd' +vagrant_UP_FILES: 'misc/hyperv/rhel-k8s-singlenode-hyperv,misc/hyperv/rhel-ose-hyperv,rhel-ose,misc/rhel-k8s-singlenode-setup' diff --git a/cdk-testsuite/impotant.txt b/cdk-testsuite/impotant.txt new file mode 100644 index 0000000..75fb2a6 --- /dev/null +++ b/cdk-testsuite/impotant.txt @@ -0,0 +1,2 @@ +netsh firewall set icmpsetting 8 enable +http://www.hurryupandwait.io/blog/understanding-and-troubleshooting-winrm-connection-and-authentication-a-thrill-seekers-guide-to-adventure diff --git a/cdk-testsuite/libraries/vagrant/vagrant.py b/cdk-testsuite/libraries/vagrant/vagrant.py index e69de29..e4a0731 100644 --- a/cdk-testsuite/libraries/vagrant/vagrant.py +++ b/cdk-testsuite/libraries/vagrant/vagrant.py @@ -0,0 +1,162 @@ +import os +import re +import time +import subprocess +import pexpect +from avocado import Test +#This is used for decoration purpose only! +dash="===================================================\n" + +#This method is used for setting up path according to your platform +def settingPath(self): + self.log.debug("Checking your machine OS") + linux = 'Linux' + win = "CYGWIN_NT-10.0" + mac = "Darwin" + p = subprocess.Popen("uname", stdout=subprocess.PIPE, shell=True) + (output, err) = p.communicate() + self.log.debug(output) + if output.strip() == linux: + self.log.debug("Using Linux yaml parameters") + var = self.params.get(linux) + self.log.debug("This is my path variable :" + var) + + elif output.strip() == win: + self.log.debug("Using win yaml parameters") + + var = self.params.get(win) + self.log.debug("This is my path variable :" + var) + + + elif output.strip() == mac: + self.log.debug("We are on Mac OS") + var = self.params.get(mac) + self.log.debug("This is my variable :" + var) + self.log.debug("This is my path variable :" + var) + + return var + +#This method is doing Vagrant up with the specific provider +def vagrantUp(self, path): + self.log.debug(" Vagrant up:: Start") + self.log.debug("changing path to " + path) + os.chdir(path) + paramerters = pexpect.spawn("vagrant up --provider "+self.params.get('vagrant_PROVIDER')) + paramerters.expect('.*Would you like to register the system now.*', timeout=250) + paramerters.sendline("y") + paramerters.expect(".*username.*") + paramerters.sendline(self.params.get('vagrant_RHN_USERNAME')) + # paramerters.sendline("naverma@redhat.com") + paramerters.expect(".*password.*") + paramerters.sendline(self.params.get('vagrant_RHN_PASSWORD')) + # paramerters.sendline("*****") + paramerters.interact() + paramerters.close() + time.sleep(20) + out=global_status(self,path) + self.assertTrue( 'running' in out) + #self.log.debug(" Vagrant up:: Exit") + + return out + +#Returning Global status +def global_status(self, vm_name): + self.log.debug("Checking Global status ::Start") + self.log.info("vagrant global-status |grep " + vm_name + " |awk '{print $4}'") + p = subprocess.Popen("vagrant global-status |grep " + vm_name + " |awk '{print $4}'", stdout=subprocess.PIPE, + shell=True) + (output, err) = p.communicate() + self.log.debug(output) + #self.log.debug("Checking Global status ::Exit") + return output,err + + +def vagrantDestroy(self,path): + self.log.info(dash + " vagrant destroy ::Start" + dash) + os.chdir(path) + p = subprocess.Popen("vagrant destroy --force", stdout=subprocess.PIPE, shell=True) + (output, err) = p.communicate() + self.log.debug(output) + self.log.info('*******************8') + #self.assertTrue('==> default: Destroying VM and associated drives' in output) + #self.log.info(dash + " vagrant destroy ::Exit" + dash) + return output,err + + +def vagrantSSH(self,command): + self.log.info(dash + "vagrant SSH :: Start" + dash) + p = subprocess.Popen("vagrant ssh -c "+command, stdout=subprocess.PIPE, shell=True) + (output, err) = p.communicate() + self.log.debug(output) + #self.log.info(dash + "vagrant SSH :: Exit" + dash) + return output + + +def vagrant_service_manager(self, path, command): + self.log.debug("vagrant_service_manager module inside Utils:: Start") + self.log.debug("changing path to " + path) + os.chdir(path) + p = subprocess.Popen("vagrant service-manager " + command) + (output, err) = p.communicate() + self.log.debug(output) + #self.log.debug("vagrant_service_manager module inside Utils:: Finish") + return output + + +def vagrant_box_add(self): + self.log.info("Vagrant Box add :: Start") + if os.path.isfile(self.params.get('vagrant_BOX_PATH')) ==True: + pass + p = subprocess.Popen('vagrant box add cdkv2 '+ str(self.params.get('vagrant_BOX_PATH'))) + (output, err) = p.communicate() + self.log.debug(output) + return output + +def vagrant_box_remove(self): + self.log.info("Vagrant Box Remove :: Start") + p = subprocess.Popen("vagrant box remove cdkv2 --force") + (output, err) = p.communicate() + self.assertTrue('Removing box' in output) + # self.log.info("Vagrant Box Remove ::Finish") + return output + +def vagrant_plugin_install(self): + try: + self.log.info("Vagrant Plugin Install :: Start") + os.chdir(self.params.get('vagrant_PLUGINS_DIR')) + #os.system("vagrant plugin install ./vagrant-registration-*.gem ./vagrant-service-manager-*.gem ./vagrant-sshfs-*.gem") + p = subprocess.Popen("vagrant plugin install ./vagrant-registration-*.gem ./vagrant-service-manager-*.gem ./vagrant-sshfs-*.gem") + (output, err) = p.communicate() + self.log.debug(output) + #return output + except: + self.log.info('Exception!') + #return output +# self.log.info("Vagrant Plugin Install ::Finish") + + + +# This method is for multi windows shell support ,it runs the specific commands in the particalar sheels +def shell_commands(self, command): + self.log.info("This method is used because we need to provide support for Powershell , cmd, cygwin, bash,ubuntu") + if self.params.get('Windows_Shell') == 'powershell': + operator = '|' + shell_output = subprocess.Popen([r'C:/WINDOWS/system32/WindowsPowerShell/v1.0/powershell.exe',command],cwd=os.getcwd()) + result = shell_output.wait + time.sleep(20) + self.log.debug('Suspend result :' + str(result)) + return shell_output + elif self.params.get('Windows_Shell') == 'cmd': + operator = '&' + shell_output = subprocess.Popen([r'C:/Windows/System32/cmd.exe',command], + cwd=os.getcwd()) + result = shell_output.wait + time.sleep(20) + self.log.debug('Suspend result :' + str(result)) + return shell_output + else: + os.chdir(self.params.get('vagrant_VARGRANTFILE_DIRS')) + shell_output = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True,cwd=os.getcwd()) + (output, err) = shell_output.communicate() + self.log.debug(output) + return output diff --git a/cdk-testsuite/libraries/vagrant/vsm.py b/cdk-testsuite/libraries/vagrant/vsm.py new file mode 100644 index 0000000..7f60e26 --- /dev/null +++ b/cdk-testsuite/libraries/vagrant/vsm.py @@ -0,0 +1,75 @@ +#!/usr/bin/python + +import os +import subprocess +from avocado.utils import process + + +def vsm_plugin_install(vagrant_PLUGIN_DIR): + ''' method installs the cdk vagrant plugins ''' + ''' returns the output of the vagrant plugin install cmd ''' + os.chdir(vagrant_PLUGIN_DIR) + cmd = "vagrant plugin install ./vagrant-registration-*.gem ./vagrant-sshfs-*.gem ./vagrant-service-manager-*.gem ./landrush-*.gem " + out = process.run(cmd, shell=True) + return out + + +def vsm_env_info(vagrant_BOX_PATH, service, readable): + ''' method to get the env variable details for + services and returns the output of the cmd ''' + os.chdir(vagrant_BOX_PATH) + cmd = "vagrant service-manager env %s %s" %(service, readable) + out = process.run(cmd, shell=True) + return out + + +def vsm_box_info(vagrant_BOX_PATH, option, readable): + ''' method to get the box version and ip details + and returns the output of the cmd ''' + try: + os.chdir(vagrant_BOX_PATH) + cmd = "vagrant service-manager box %s %s" %(option, readable) + out = process.run(cmd, shell=True) + return out + except: + print "Could NOT get the info of the Vagrant box. Maybe something went wrong..." + +def vsm_service_handling(vagrant_BOX_PATH, operation, service): + ''' method to start/stop/restart and get status of + services and returns the output of the cmd ''' + os.chdir(vagrant_BOX_PATH) + cmd = "vagrant service-manager %s %s" %(operation, service) + out = process.run(cmd, shell=True) + return out + + +def vsm_is_service_running(vagrant_BOX_PATH, service): + ''' checks status of service and returns True if running ''' + try: + os.chdir(vagrant_BOX_PATH) + cmd = "vagrant service-manager status %s" %(service) + out = process.run(cmd, shell=True) + if "%s - running\n" %(service) == out.stdout: + return True + elif "%s - stopped\n" %(service) == out.stdout: + return False + except: + print "Could NOT get the status of the service. Maybe something went wrong..." + +def instll_cli(vagrant_BOX_PATH, service,version,command): + os.chdir(vagrant_BOX_PATH) + env_vars = subprocess.Popen('eval "$(VAGRANT_NO_COLOR=1 vagrant service-manager env '+service+' | tr -d \'\r\')";eval "$(vagrant service-manager install-cli '+service+' '+version+' | tr -d \'\r\')";'+command+'', stdout=subprocess.PIPE, shell=True) + (output1, err1) = env_vars.communicate() + return output1,err1 + +def box_ip(vagrant_BOX_PATH, ip): + os.chdir(vagrant_BOX_PATH) + env_vars = subprocess.Popen("vagrant service-manager box %s " %(ip), stdout=subprocess.PIPE, shell=True) + (output1, err1) = env_vars.communicate() + return output1,err1 + + + + + + diff --git a/cdk-testsuite/tests/README.md b/cdk-testsuite/tests/README.md index e69de29..b5ba76e 100644 --- a/cdk-testsuite/tests/README.md +++ b/cdk-testsuite/tests/README.md @@ -0,0 +1 @@ +# avocado run test.py --multiplex congfig.yaml_path diff --git a/cdk-testsuite/tests/VagrantSanity.py b/cdk-testsuite/tests/VagrantSanity.py new file mode 100644 index 0000000..47c1fb4 --- /dev/null +++ b/cdk-testsuite/tests/VagrantSanity.py @@ -0,0 +1,133 @@ +import time +from avocado import Test +import imp +Utils = imp.load_source('Utils', '/cygdrive/c/Users/naina/Downloads/ACDK/ACDK/Logic/Utils.py') + +class VagrantTests(Test): + + + + def test(self): + sleep_length = self.params.get('sleep_length', default=1) + self.log.debug("Sleeping for %.2f seconds", sleep_length) + time.sleep(sleep_length) + path_var=Utils.settingPath(self) + self.log.debug(str(path_var)) + + + def Rhel_ose_up(self): + self.log.info("Getting Path to CDK directory") + + path_var = Utils.settingPath(self) + try: + globalstatus = Utils.global_status(self,"rhel-ose") + self.log.info("Status of " + path_var + 'rhel-ose' + " " + globalstatus.strip()) + except: + self.log.info("Exception!!") + globalstatus='none' + finally: + + if(globalstatus.strip() !='running'): + self.log.info("Status of " + path_var + 'rhel-ose' + " " + globalstatus) + + (output, err) = Utils.vagrantUp(self, path_var + 'rhel-ose') + self.log.debug(output) + self.log.debug(err) + time.sleep(40) + self.log.debug("Sleep for 40 seconds : Before checking global status") + globalstatus = Utils.global_status(self, "rhel-ose") + self.log.info("Status of " + path_var + 'rhel-ose' + " " + globalstatus) + assert globalstatus.strip(),'running' + + elif(globalstatus.strip() =='running'): + + globalstatus=Utils.global_status(self, "rhel-ose") + self.log.info("Status of "+path_var + 'rhel-ose'+" "+globalstatus) + + def test_Rhel_k8_up(self): + self.log.info("Getting Path to CDK directory") + + path_var = Utils.settingPath(self) + try: + globalstatus = Utils.global_status(self, "misc/rhel-k8s-singlenode-setup") + self.log.info("Status of " + path_var + 'misc/rhel-k8s-singlenode-setup' + " " + globalstatus.strip()) + except Exception: + self.log.info("Exception!!") + globalstatus = 'none' + finally: + + if (globalstatus.strip() != 'running'): + self.log.info("Status of " + path_var + 'misc/rhel-k8s-singlenode-setup' + " " + globalstatus) + + (output, err) = Utils.vagrantUp(self, path_var + 'misc/rhel-k8s-singlenode-setup') + #self.log.debug(output) + #self.log.debug(err) + time.sleep(40) + self.log.debug("Sleep for 40 seconds : Before checking global status") + globalstatus = Utils.global_status(self, "misc/rhel-k8s-singlenode-setup") + self.log.info("Status of " + path_var + 'misc/rhel-k8s-singlenode-setup' + " " + globalstatus) + assert globalstatus.strip(), 'running' + + elif (globalstatus.strip() == 'running'): + + globalstatus = Utils.global_status(self, "misc/rhel-k8s-singlenode-setup") + self.log.info("Status of " + path_var + 'misc/rhel-k8s-singlenode-setup' + " " + globalstatus) + + def test_Rhel_ose_hyperv_up(self): + self.log.info("Getting Path to CDK directory") + + path_var = Utils.settingPath(self) + try: + globalstatus = Utils.global_status(self, "misc/rhel-k8s-singlenode-setup") + self.log.info("Status of " + path_var + 'misc/rhel-k8s-singlenode-setup' + " " + globalstatus.strip()) + except Exception: + self.log.info("Exception!!") + globalstatus = 'none' + finally: + + if (globalstatus.strip() != 'running'): + self.log.info("Status of " + path_var + 'misc/hyperv/rhel-ose-hyperv' + " " + globalstatus) + + (output, err) = Utils.vagrantUp(self, path_var + 'misc/hyperv/rhel-ose-hyperv') + # self.log.debug(output) + # self.log.debug(err) + time.sleep(40) + self.log.debug("Sleep for 40 seconds : Before checking global status") + globalstatus = Utils.global_status(self, "misc/hyperv/rhel-ose-hypervp") + self.log.info("Status of " + path_var + 'misc/hyperv/rhel-ose-hyperv' + " " + globalstatus) + assert globalstatus.strip(), 'running' + + elif (globalstatus.strip() == 'running'): + + globalstatus = Utils.global_status(self, "misc/hyperv/rhel-ose-hyperv") + self.log.info("Status of " + path_var + 'misc/hyperv/rhel-ose-hyperv' + " " + globalstatus) + + def test_Rhel_hyper_k8_up(self): + self.log.info("Getting Path to CDK directory") + + path_var = Utils.settingPath(self) + try: + globalstatus = Utils.global_status(self, "misc/hyperv/rhel-k8s-singlenode-hyperv") + self.log.info("Status of " + path_var + 'misc/hyperv/rhel-k8s-singlenode-hyperv' + " " + globalstatus.strip()) + except Exception: + self.log.info("Exception!!") + globalstatus = 'none' + finally: + + if (globalstatus.strip() != 'running'): + self.log.info("Status of " + path_var + 'misc/hyperv/rhel-k8s-singlenode-hyperv' + " " + globalstatus) + + (output, err) = Utils.vagrantUp(self, path_var + 'misc/hyperv/rhel-k8s-singlenode-hyperv') + # self.log.debug(output) + # self.log.debug(err) + time.sleep(40) + self.log.debug("Sleep for 40 seconds : Before checking global status") + globalstatus = Utils.global_status(self, "misc/hyperv/rhel-k8s-singlenode-hyperv") + self.log.info("Status of " + path_var + 'misc/hyperv/rhel-k8s-singlenode-hyperv' + " " + globalstatus) + assert globalstatus.strip(), 'running' + + elif (globalstatus.strip() == 'running'): + + globalstatus = Utils.global_status(self, "misc/hyperv/rhel-k8s-singlenode-hyperv") + self.log.info("Status of " + path_var + 'misc/hyperv/rhel-k8s-singlenode-hyperv' + " " + globalstatus) + diff --git a/cdk-testsuite/tests/cdk_dependencies_check.py b/cdk-testsuite/tests/cdk_dependencies_check.py new file mode 100644 index 0000000..2bea811 --- /dev/null +++ b/cdk-testsuite/tests/cdk_dependencies_check.py @@ -0,0 +1,54 @@ +import time +from avocado import Test +import subprocess +import imp +import vagrant +cdk_utils = imp.load_source('cdk_utils', '../utils/cdk_dependency_util.py') +class cdk_dependencies_check(Test): + + + def test_vagrant_verification(self): + self.log.info("Checking which operating system are you using::") + machine = cdk_utils.platform_verification(self) + self.log.info("Verifying Vagrant for :: " +machine) + vagrant_verification = vagrant.Vagrant() + try: + vagrant_VERSION=vagrant_verification.version() + self.log.info("Vagrant version is :: " + vagrant_VERSION) + self.assertTrue(vagrant_VERSION) + except: + self.log.info("Vagrant is not present on Machine ") + cdk_utils.vagrant_installation(self,machine=machine,sudopassword=self.params.get('SudoPassword')) + time.sleep(30) + vagrant_VERSION = vagrant_verification.version() + self.log.info("Vagrant version is :: " + vagrant_VERSION) + self.assertTrue(vagrant_VERSION) + + def test_enable_virtualization_verification(self): + self.log.info("Testing Enable Virtualization") + self.log.info("Checking which operating system are you using::") + machine = cdk_utils.platform_verification(self) + self.log.info("Verifying Vagrant for :: " +machine) + vagrant_verification = vagrant.Vagrant() + + try: + cdk_utils.enable_virtualization(self,machine=machine,sudopassword=self.params.get('SudoPassword'),sub_username=self.params.get('vagrant_RHN_USERNAME'),sub_password=self.params.get('vagrant_RHN_PASSWORD')) + except: + print "anything" + + def test_virtualbox(self): + self.log.info("Verification check for virtual box installation") + self.log.info("Checking which operating system are you using::") + machine = cdk_utils.platform_verification(self) + cdk_utils.virtualbox_installation(self,machine=machine,sudopassword=self.params.get('SudoPassword')) + +if __name__ == '__main__': + print "working" + #test_vagrant_verification(self) + + + + + + + diff --git a/cdk-testsuite/tests/cmd.py b/cdk-testsuite/tests/cmd.py new file mode 100644 index 0000000..bb6f0b8 --- /dev/null +++ b/cdk-testsuite/tests/cmd.py @@ -0,0 +1,107 @@ +import time +import imp +from avocado import Test +import subprocess +import os +import pexpect +#from Logic import vagrant_lib + +vagrant_lib= imp.load_source('vagrant_lib', '../libraries/vagrant/vagrant.py') + +class cmd(Test): + + + + + + def test_vagrant_up(self): + self.log.info("Getting Path to CDK directory") + vagrnat_up_dirs=self.params.get('vagrant_UP_FILES') + self.log.info('These are the locations of Vagrant files ::') + + for x in vagrnat_up_dirs.split(',') : + self.log.info(x) + path_var = self.params.get('vagrant_VARGRANTFILE_DIRS') + try: + (output, err) = vagrant_lib.vagrantUp(self, path_var + x) + self.log.debug("Sleep for 40 seconds : Before checking global status") + globalstatus = vagrant_lib.global_status(self, path_var+x) + self.log.info("Status of 1" + path_var + x + " " + globalstatus+"***") + assert globalstatus, 'running' + + except Exception: + self.log.info("Exception!!") + + finally: + globalstatus = vagrant_lib.global_status(self,path_var+ x) + self.log.info("Status of 2" + path_var + x + " " + str( globalstatus )+"***") + if 'running' in globalstatus : + self.log.info("Status of " + path_var + x + " " +str( globalstatus)+"***") + (output, err) = vagrant_lib.vagrantUp(self, path_var + x) + self.log.debug("Sleep for 40 seconds : Before checking global status") + time.sleep(40) + globalstatus = vagrant_lib.global_status(self, path_var+x) + self.log.info("Status of 3" + path_var + x + " " + str(globalstatus)) + assert globalstatus, 'running' + + + + elif 'running' not in globalstatus : + + globalstatus = vagrant_lib.global_status(self,path_var+ x) + self.log.info("Status of " + path_var + x + " " + str(globalstatus)) + + + + def test_k8_powershell_status(self): + if self.params.get('Windows_Shell') == 'powershell': + operator = '|' + elif self.params.get('Windows_Shell') == 'cmd': + operator = '&' + else: + operator='&&' + vagrnat_up_dirs=self.params.get('vagrant_UP_FILES') + self.log.info('These are the locations of Vagrant files ::') + + for x in vagrnat_up_dirs.split(',') : + + output=vagrant_lib.shell_commands(self,'cd ' + self.params.get('vagrant_VARGRANTFILE_DIRS') + x+' ' + operator + ' vagrant status' ) + self.assertTrue('running' in output) + + + + + def test_k8_powershell_resume(self): + if self.params.get('Windows_Shell') == 'powershell': + operator = '|' + elif self.params.get('Windows_Shell') == 'cmd': + operator = '&' + else: + operator='&&' + vagrnat_up_dirs=self.params.get('vagrant_UP_FILES') + self.log.info('These are the locations of Vagrant files ::') + + for x in vagrnat_up_dirs.split(',') : + output=vagrant_lib.shell_commands(self, 'cd ' + self.params.get('vagrant_VARGRANTFILE_DIRS') + x+' ' + operator + 'vagrant resume') + self.assertTrue('Resuming' in output) + + + def test_k8_powershell_destroy(self): + if self.params.get('Windows_Shell') == 'powershell': + operator = '|' + elif self.params.get('Windows_Shell') == 'cmd': + operator = '&' + else: + operator='&&' + vagrnat_up_dirs=self.params.get('vagrant_UP_FILES') + self.log.info('These are the locations of Vagrant files ::') + + for x in vagrnat_up_dirs.split(',') : + output=vagrant_lib.shell_commands(self, 'cd ' + self.params.get('vagrant_VARGRANTFILE_DIRS') + x+' ' + operator + 'vagrant destroy --force') + self.assertTrue('Deleting' in output) + + + + + + diff --git a/cdk-testsuite/tests/service_manager.py b/cdk-testsuite/tests/service_manager.py new file mode 100644 index 0000000..8ff35ed --- /dev/null +++ b/cdk-testsuite/tests/service_manager.py @@ -0,0 +1,162 @@ +#!/usr/bin/python + +from avocado import Test +from avocado import main +from avocado.utils import process +import re, os, imp, vagrant, pexpect, re ,time +import subprocess +vsm = imp.load_source('vsm', '../Logic/vsm.py') + + +class service_manager(Test): + def setUp(self): + self.log.info("setup") + self.vagrant_VAGRANTFILE_DIR=self.params.get('vagrant_VAGRANTFILE_DIR') + self.vagrant_PLUGIN_PATH=self.params.get('vagrant_PLUGIN_PATH') + self.service = self.params.get('service', default='') + self.vagrant_PROVIDER = self.params.get('vagrant_PROVIDER', default='hyperv') + os.chdir(self.vagrant_VAGRANTFILE_DIR) + self.v = vagrant.Vagrant(self.vagrant_VAGRANTFILE_DIR) + + def test_cdkbox_version(self): + output = vsm.vsm_box_info(self.vagrant_VAGRANTFILE_DIR, "version", "--script-readable") + print output + self.assertIn("Container Development Kit (CDK)",output.stdout) + + def test_vsm_box_ip(self): + output = vsm.vsm_box_info(self.vagrant_VAGRANTFILE_DIR, "ip", "") + ip = output.stdout + ips = re.findall('(?:[\d]{1,3})\.(?:[\d]{1,3})\.(?:[\d]{1,3})\.(?:[\d]{1,3})',ip) + print ips[0] + self.assertTrue(ips[0]) + + def test_env_info_docker(self): + + output = vsm.vsm_env_info(self.vagrant_VAGRANTFILE_DIR, "docker","--script-readable") + print output.stdout + self.assertIn("DOCKER_HOST" and "DOCKER_CERT_PATH" and "DOCKER_TLS_VERIFY" and "DOCKER_API_VERSION" , output.stdout) + + + def test_env_info_openshift(self): + output = vsm.vsm_env_info(self.vagrant_VAGRANTFILE_DIR, "openshift","--script-readable") + print output.stdout + self.assertIn("OPENSHIFT_URL" and "OPENSHIFT_WEB_CONSOLE" and "DOCKER_REGISTRY" , output.stdout) + + + def test_vsm_status_of_docker_service_running(self): + output = vsm.vsm_service_handling(self.vagrant_VAGRANTFILE_DIR, "status", "docker") + print output.stdout + self.assertIn("docker - running",output.stdout) + + + def test_vsm_status_openshift_service_running(self): + output = vsm.vsm_service_handling(self.vagrant_VAGRANTFILE_DIR, "status", "openshift") + print output.stdout + self.assertIn("openshift - running",output.stdout) + + + + def test_stop_openshift_service_start_again(self): + vsm.vsm_service_handling(self.vagrant_VAGRANTFILE_DIR, "stop", "openshift") + output = vsm.vsm_service_handling(self.vagrant_VAGRANTFILE_DIR, "status", "openshift") + print output.stdout + if "openshift - stopped" in output.stdout: + restart = vsm.vsm_service_handling(self.vagrant_VAGRANTFILE_DIR, "start", "openshift") + time.sleep(20) + output = vsm.vsm_service_handling(self.vagrant_VAGRANTFILE_DIR, "status", "openshift") + + self.assertIn("openshift - running" , output.stdout) + + else: + self.assertTrue("openshift - running" , output.stdout) + + def test_stop_docker_service_start_again(self): + vsm.vsm_service_handling(self.vagrant_VAGRANTFILE_DIR, "stop", "docker") + output = vsm.vsm_service_handling(self.vagrant_VAGRANTFILE_DIR, "status", "docker") + print output.stdout + if "docker - stopped" in output.stdout: + restart = vsm.vsm_service_handling(self.vagrant_VAGRANTFILE_DIR, "start", "docker") + time.sleep(20) + output = vsm.vsm_service_handling(self.vagrant_VAGRANTFILE_DIR, "status", "") + if "docker - running" and "openshift - running" in output.stdout: + pass + else: + restart = vsm.vsm_service_handling(self.vagrant_VAGRANTFILE_DIR, "restart", "docker") + time.sleep(30) + output = vsm.vsm_service_handling(self.vagrant_VAGRANTFILE_DIR, "status", "") + + self.assertIn("docker - running" and "openshift - running" , output.stdout) + + + else: + self.assertIn("docker - running" , output.stdout) + + + + + def test_docker_version_host(self): + (out,err)=vsm.instll_cli(self.vagrant_VAGRANTFILE_DIR, "docker",'', "docker version") + print out,err + self.assertIn('Client' and 'Server',out) + + + def test_docker_images_host(self): + (out,err)=vsm.instll_cli(self.vagrant_VAGRANTFILE_DIR, "docker", '',"docker images") + print out,err + self.assertIn('registry.access.redhat.com',out) + + + def test_docker_ps(self): + (out,err)=vsm.instll_cli(self.vagrant_VAGRANTFILE_DIR, "docker",'', "docker ps") + print out,err + self.assertIn('openshift',out) + + def test_docker_pull(self): + (out,err)=vsm.instll_cli(self.vagrant_VAGRANTFILE_DIR, "docker", '',"docker pull tutum/hello-world") + print out,err + self.assertIn('Status: Downloaded newer image for docker.io/tutum/hello-world:latest',out) + + + def test_docker_rmi(self): + (out,err)=vsm.instll_cli(self.vagrant_VAGRANTFILE_DIR, "docker",'', "docker rmi tutum/hello-world") + print out,err + self.assertIn('Deleted',out) + + + def test_openshift_from_host_version(self): + + (out,err)=vsm.instll_cli(self.vagrant_VAGRANTFILE_DIR, "openshift",'', "oc version") + print out,err + self.assertIn('oc v1.2.1',out) + + def test_openshift_from_host_version(self): + + (out,err)=vsm.instll_cli(self.vagrant_VAGRANTFILE_DIR, "openshift", '',"oc version") + print out,err + self.assertIn('oc v1.2.1',out) + + def test_openshift_login_host(self): + (out,err)=vsm.box_ip(self.vagrant_VAGRANTFILE_DIR,'ip') + out=out.replace('ESC[0m','') + ips = re.findall('(?:[\d]{1,3})\.(?:[\d]{1,3})\.(?:[\d]{1,3})\.(?:[\d]{1,3})',out) + print ips[0] + (out,err)=vsm.instll_cli(self.vagrant_VAGRANTFILE_DIR, "openshift",'', "oc login " +ips[0]+" --username=openshift-dev "+" --password=devel --insecure-skip-tls-verify") + print out,err + self.assertIn('Login successful',out) + + + + def test_openshift_newproject_host(self): + (out,err)=vsm.box_ip(self.vagrant_VAGRANTFILE_DIR,'ip') + out=out.replace('ESC[0m','') + ips = re.findall('(?:[\d]{1,3})\.(?:[\d]{1,3})\.(?:[\d]{1,3})\.(?:[\d]{1,3})',out) + print ips[0] + (out,err)=vsm.instll_cli(self.vagrant_VAGRANTFILE_DIR, "openshift",'', "oc login " +ips[0]+" --username=openshift-dev "+" --password=devel --insecure-skip-tls-verify;oc new-project test-project") + print out,err + self.assertIn('test-project',out) + + + def test_install_cli_with_versions(self): + (out,err)=vsm.instll_cli(self.vagrant_VAGRANTFILE_DIR, "docker",'--cli-version 1.12.1', "docker version") + print out,err + self.assertIn('1.12.1',out) diff --git a/cdk-testsuite/utils/Utils.py b/cdk-testsuite/utils/Utils.py new file mode 100644 index 0000000..899cd1a --- /dev/null +++ b/cdk-testsuite/utils/Utils.py @@ -0,0 +1,151 @@ +import os +import re +import time +import subprocess +import pexpect +from avocado import Test +#This is used for decoration purpose only! +dash="===================================================\n" + +#This method is used for setting up path according to your platform +def settingPath(self): + self.log.debug("Checking your machine OS") + linux = 'Linux' + win = "CYGWIN_NT-10.0" + mac = "Darwin" + p = subprocess.Popen("uname", stdout=subprocess.PIPE, shell=True) + (output, err) = p.communicate() + self.log.debug(output) + if output.strip() == linux: + self.log.debug("Using Linux yaml parameters") + var = self.params.get(linux) + self.log.debug("This is my path variable :" + var) + + elif output.strip() == win: + self.log.debug("Using win yaml parameters") + + var = self.params.get(win) + self.log.debug("This is my path variable :" + var) + + + elif output.strip() == mac: + self.log.debug("We are on Mac OS") + var = self.params.get(mac) + self.log.debug("This is my variable :" + var) + self.log.debug("This is my path variable :" + var) + + return var + +#This method is doing Vagrant up with the specific provider +def vagrantUp(self, path): + self.log.debug(" Vagrant up:: Start") + self.log.debug("changing path to " + path) + os.chdir(path) + paramerters = pexpect.spawn("vagrant up --provider "+self.params.get('vagrant_PROVIDER')) + paramerters.expect('.*Would you like to register the system now.*', timeout=150) + paramerters.sendline("y") + paramerters.expect(".*username.*") + paramerters.sendline(self.params.get('vagrant_RHN_USERNAME')) + # paramerters.sendline("naverma@redhat.com") + paramerters.expect(".*password.*") + paramerters.sendline(self.params.get('vagrant_RHN_PASSWORD')) + # paramerters.sendline("*****") + paramerters.interact() + paramerters.close() + #self.log.debug(" Vagrant up:: Exit") + + return 'ok' + +#Returning Global status +def global_status(self, vm_name): + self.log.debug("Checking Global status ::Start") + p = subprocess.Popen("vagrant global-status |grep " + vm_name + "|awk '{print $4}'", stdout=subprocess.PIPE, + shell=True) + (output, err) = p.communicate() + self.log.debug(output) + #self.log.debug("Checking Global status ::Exit") + return output + + +def vagrantDestroy(self): + self.log.info(dash + " vagrant destroy ::Start" + dash) + p = subprocess.Popen("vagrant destroy", stdout=subprocess.PIPE, shell=True) + (output, err) = p.communicate() + self.log.debug(output) + #self.log.info(dash + " vagrant destroy ::Exit" + dash) + return output + + +def vagrantSSH(self,command): + self.log.info(dash + "vagrant SSH :: Start" + dash) + p = subprocess.Popen("vagrant ssh -c "+command, stdout=subprocess.PIPE, shell=True) + (output, err) = p.communicate() + self.log.debug(output) + #self.log.info(dash + "vagrant SSH :: Exit" + dash) + return output + + +def vagrant_service_manager(self, path, command): + self.log.debug("vagrant_service_manager module inside Utils:: Start") + self.log.debug("changing path to " + path) + os.chdir(path) + p = subprocess.Popen("vagrant service-manager " + command) + (output, err) = p.communicate() + self.log.debug(output) + #self.log.debug("vagrant_service_manager module inside Utils:: Finish") + return output + + +def vagrant_box_add(self): + self.log.info("Vagrant Box add :: Start") + p = subprocess.Popen("vagrant box add cdkv2 " + self.params.get('vagrant_BOX_PATH')) + (output, err) = p.communicate() + self.log.debug(output) + # self.log.info("Vagrant Box add ::Finish") + return output + +def vagrant_box_remove(self): + self.log.info("Vagrant Box Remove :: Start") + p = subprocess.Popen("vagrant box remove cdkv2 --force") + (output, err) = p.communicate() + self.log.debug(output) + # self.log.info("Vagrant Box Remove ::Finish") + return output + +def vagrant_plugin_install(self): + self.log.info("Vagrant Plugin Install :: Start") + os.chdir(self.params.get('vagrant_PLUGINS_DIR')) + os.system("vagrant plugin install ./vagrant-registration-*.gem ./vagrant-service-manager-*.gem ./vagrant-sshfs-*.gem") + p = subprocess.Popen("vagrant plugin install ./vagrant-registration-*.gem ./vagrant-service-manager-*.gem ./vagrant-sshfs-*.gem") + (output, err) = p.communicate() + self.log.debug(output) +# self.log.info("Vagrant Plugin Install ::Finish") + + return output + +# This method is for multi windows shell support ,it runs the specific commands in the particalar sheels +def shell_commands(self, command): + self.log.info("This method is used because we need to provide support for Powershell , cmd, cygwin, bash,ubuntu") + if self.params.get('Windows_Shell') == 'powershell': + operator = '|' + psxmlgen = subprocess.Popen([r'C:/WINDOWS/system32/WindowsPowerShell/v1.0/powershell.exe', + 'cd ' + self.params.get( + 'vagrant_VARGRANTFILE_DIRS') + 'misc/hyperv/rhel-k8s-singlenode-hyperv ' + operator + ' ' + command], + cwd=os.getcwd()) + result = psxmlgen.wait + time.sleep(20) + self.log.debug('Suspend result :' + str(result)) + elif self.params.get('Windows_Shell') == 'cmd': + operator = '&' + psxmlgen = subprocess.Popen([r'C:/Windows/System32/cmd.exe', + 'cd ' + self.params.get( + 'vagrant_VARGRANTFILE_DIRS') + 'misc/hyperv/rhel-k8s-singlenode-hyperv ' + operator + ' ' + command], + cwd=os.getcwd()) + result = psxmlgen.wait + time.sleep(20) + self.log.debug('Suspend result :' + str(result)) + + + + + diff --git a/cdk-testsuite/utils/avocado-36.0lts.zip b/cdk-testsuite/utils/avocado-36.0lts.zip new file mode 100644 index 0000000..e35a011 Binary files /dev/null and b/cdk-testsuite/utils/avocado-36.0lts.zip differ diff --git a/cdk-testsuite/utils/cdk_dependency_util.py b/cdk-testsuite/utils/cdk_dependency_util.py new file mode 100644 index 0000000..fcec55c --- /dev/null +++ b/cdk-testsuite/utils/cdk_dependency_util.py @@ -0,0 +1,160 @@ +import time +from avocado import Test +import subprocess +import imp +import os +Utils = imp.load_source('Utils', '../utils/Utils.py') + +def platform_verification(self): + self.log.info("Checking which operating system are you using::") + p = subprocess.Popen("uname -a", stdout=subprocess.PIPE, shell=True) + (output, err) = p.communicate() + self.log.debug(output) + if "Linux" in output: + self.log.debug("Operating System name is :: " + output) + return "Linux" + elif "CYGWIN" in output: + self.log.debug("Operating System name is :: " + output) + return "CYGWIN " + elif "Darwin" in output: + self.log.debug("Operating System name is :: " + output) + return "Darwin" + +def vagrant_installation(self,machine=None,sudopassword=None): + self.log.info("Downloading Vagrant on Machine ::" +machine) + if machine == "Linux": + p = subprocess.Popen("lsb_release -a", stdout=subprocess.PIPE, shell=True) + (output, err) = p.communicate() + self.log.debug(output) + if "Fedora" in output: + self.log.info("Vagrant binary downloading on "+machine) + self.log.info("echo "+str(sudopassword)+" | sudo -S yum install vagrant -y") + os.system("echo "+str(sudopassword)+" | sudo -S yum install vagrant -y") + elif "CYGWIN" in machine: + self.log.info("Vagrant binary downloading on " + machine) + if not os.path.isfile('./vagrant_1.8.4.msi'): + self.log.info('wget https://releases.hashicorp.com/vagrant/1.8.4/vagrant_1.8.4.msi') + p = subprocess.Popen('wget https://releases.hashicorp.com/vagrant/1.8.4/vagrant_1.8.4.msi', stdout=subprocess.PIPE, shell=True) + (output, err) = p.communicate() + self.log.debug(output) + else: + os.system('msiexec.exe /a vagrant_1.8.4.msi') + time.sleep(30) + self.log.info('') + elif "Darwin" in machine: + self.log.info("Vagrant binary downloading on " + machine) + self.log.info("Under construction!!") + + +def enable_virtualization(self,machine=None,sudopassword=None,sub_username=None,sub_password=None): + self.log.info("Enableing virtualization on machine "+machine) + if machine == "Linux": + p = subprocess.Popen("lsb_release -a", stdout=subprocess.PIPE, shell=True) + (output, err) = p.communicate() + self.log.debug(output) + if "Fedora" in output: + self.log.info("The linux machine is "+str(output)) + self.log.info("echo "+str(sudopassword)+" | sudo -S dnf -y update") + os.system("echo "+str(sudopassword)+" | sudo -S dnf -y update") + ## Enable Virtualization + self.log.info("echo "+str(sudopassword)+" | sudo -S dnf install @Virtualization") + os.system("echo "+str(sudopassword)+" | sudo -S dnf install @Virtualization") + ### Launch the libvirt daemon and configure it to start at boot. + self.log.info("echo "+str(sudopassword)+" | sudo -S systemctl start libvirtd") + os.system("echo "+str(sudopassword)+" | sudo -S systemctl start libvirtd") + self.log.info("echo "+str(sudopassword)+" | sudo -S systemctl enable libvirtd") + os.system("echo "+str(sudopassword)+" | sudo -S systemctl enable libvirtd") + + ### Install Vagrant and other required packages, including the vagrant-registration and vagrant-libvirt plugins: + self.log.info("echo "+str(sudopassword)+" | sudo -S dnf install vagrant vagrant-libvirt vagrant-libvirt-doc vagrant-registration rubygem-ruby-libvirt") + os.system("echo "+str(sudopassword)+" | sudo -S dnf install vagrant vagrant-libvirt vagrant-libvirt-doc vagrant-registration rubygem-ruby-libvirt") + ### vagrant group to control VMs through libvirt + self.log.info("echo "+str(sudopassword)+" | sudo -S cp /usr/share/vagrant/gems/doc/vagrant-libvirt-0.0.*/polkit/10-vagrant-libvirt.rules /etc/polkit-1/rules.d") + os.system("echo "+str(sudopassword)+" | sudo -S cp /usr/share/vagrant/gems/doc/vagrant-libvirt-0.0.*/polkit/10-vagrant-libvirt.rules /etc/polkit-1/rules.d") + ### Restart the libvirt and PolicyKit services for the changes to take effect: + self.log.info("echo "+str(sudopassword)+" | sudo -S systemctl restart libvirtd") + os.system("echo "+str(sudopassword)+" | sudo -S systemctl restart libvirtd") + self.log.info("echo "+str(sudopassword)+" | sudo -S systemctl restart polkit") + os.system("echo "+str(sudopassword)+" | sudo -S systemctl restart polkit") + ### check vagrant global-status after that + + elif "RedHat" in output: + self.log.info("The linux machine is "+str(output)) + ### Adding Redhat subscription + + p = subprocess.Popen("subscription-manager register --auto-attach --username="+sub_username+" --password="+sub_password, stdout=subprocess.PIPE, shell=True) + (output, err) = p.communicate() + self.log.debug(output) + + p1 = subprocess.Popen("subscription-manager repos --enable rhel-variant-rhscl-7-rpms", stdout=subprocess.PIPE, shell=True) + (output1, err1) = p1.communicate() + self.log.debug(output1) + + p2 = subprocess.Popen("subscription-manager repos --enable rhel-7-variant-optional-rpms", stdout=subprocess.PIPE, shell=True) + (output2, err2) = p2.communicate() + self.log.debug(output2) + + p3 = subprocess.Popen("yum-config-manager --add-repo=http://mirror.centos.org/centos-7/7/sclo/x86_64/sclo/", stdout=subprocess.PIPE, shell=True) + (output3, err3) = p3.communicate() + self.log.debug(output3) + + p4 = subprocess.Popen("echo \"gpgcheck=0\" >> /etc/yum.repos.d/mirror.centos.org_centos-7_7_sclo_x86_64_sclo_.repo", stdout=subprocess.PIPE, shell=True) + (output4, err4) = p4.communicate() + self.log.debug(output4) + + self.log.info("echo "+str(sudopassword)+" | sudo -S yum -y update") + os.system("echo "+str(sudopassword)+" | sudo -S yum -y update") + ## Enable Virtualization + self.log.info("echo "+str(sudopassword)+" | sudo -S yum groupinstall -y \"Virtualization Host\"") + os.system("echo "+str(sudopassword)+" | sudo -S yum groupinstall -y \"Virtualization Host\"") + ### Launch the libvirt daemon and configure it to start at boot. + self.log.info("echo "+str(sudopassword)+" | sudo -S dnf install @Virtualization") + os.system("echo "+str(sudopassword)+" | sudo -S dnf install @Virtualization") + self.log.info("echo "+str(sudopassword)+" | sudo -S systemctl start libvirtd") + os.system("echo "+str(sudopassword)+" | sudo -S systemctl start libvirtd") + self.log.info("echo "+str(sudopassword)+" | sudo -S systemctl enable libvirtd") + os.system("echo "+str(sudopassword)+" | sudo -S systemctl enable libvirtd") + ### Install Vagrant and other required packages, including the vagrant-registration and vagrant-libvirt plugins: + self.log.info("echo "+str(sudopassword)+" | sudo -S yum install sclo-vagrant1 sclo-vagrant1-vagrant-libvirt sclo-vagrant1-vagrant-libvirt-doc sclo-vagrant1-vagrant-registration") + os.system("echo "+str(sudopassword)+" | sudo -S yum install sclo-vagrant1 sclo-vagrant1-vagrant-libvirt sclo-vagrant1-vagrant-libvirt-doc sclo-vagrant1-vagrant-registration") + + ### vagrant group to control VMs through libvirt + self.log.info("cp /opt/rh/sclo-vagrant1/root/usr/share/vagrant/gems/doc/vagrant-libvirt-*/polkit/10-vagrant-libvirt.rules /etc/polkit-1/rules.d") + os.system("cp /opt/rh/sclo-vagrant1/root/usr/share/vagrant/gems/doc/vagrant-libvirt-*/polkit/10-vagrant-libvirt.rules /etc/polkit-1/rules.d") + ### Restart the libvirt and PolicyKit services for the changes to take effect: + self.log.info("echo "+str(sudopassword)+" | sudo -S systemctl restart libvirtd") + os.system("echo "+str(sudopassword)+" | sudo -S systemctl restart libvirtd") + self.log.info("echo "+str(sudopassword)+" | sudo -S systemctl restart polkit") + os.system("echo "+str(sudopassword)+" | sudo -S systemctl restart polkit") + ### check vagrant global-status after that + else: + self.log.info("Something went wrong !!") + + elif "CYGWIN" in machine: + self.log.info(" This is an Windows machine with complete name :: " + machine) + ## Utils.sh_cmd() Continue.. with hyper - V if enabled + + elif "Darwin" in machine: + self.log.info("Vagrant binary downloading on " + machine) + self.log.info("Under construction!!") + + + + +def virtualbox_installation(self,machine=None,sudopassword=None): + self.log.info("Downloading Vagrant on Machine ::" +machine) + if machine == "Linux": + # Not implimented yet + self.log.info("virtualbox this part is already done in Installing virtualization ::s "+machine) + + elif "CYGWIN" in machine: + # Not implimented yet + self.log.info("virtualbox binary should be already present on your :: " + machine) + + elif "Darwin" in machine: + # Not implimented yet + self.log.info("virtualbox binary should be already present on your :: " + machine) + + + + diff --git a/cdk-testsuite/utils/vagrant_utils.py b/cdk-testsuite/utils/vagrant_utils.py new file mode 100644 index 0000000..2d2c729 --- /dev/null +++ b/cdk-testsuite/utils/vagrant_utils.py @@ -0,0 +1,162 @@ +import os +import re +import time +import subprocess +import pexpect +from avocado import Test +#This is used for decoration purpose only! +dash="===================================================\n" + +#This method is used for setting up path according to your platform +def settingPath(self): + self.log.debug("Checking your machine OS") + linux = 'Linux' + win = "CYGWIN_NT-10.0" + mac = "Darwin" + p = subprocess.Popen("uname", stdout=subprocess.PIPE, shell=True) + (output, err) = p.communicate() + self.log.debug(output) + if output.strip() == linux: + self.log.debug("Using Linux yaml parameters") + var = self.params.get(linux) + self.log.debug("This is my path variable :" + var) + + elif output.strip() == win: + self.log.debug("Using win yaml parameters") + + var = self.params.get(win) + self.log.debug("This is my path variable :" + var) + + + elif output.strip() == mac: + self.log.debug("We are on Mac OS") + var = self.params.get(mac) + self.log.debug("This is my variable :" + var) + self.log.debug("This is my path variable :" + var) + + return var + +#This method is doing Vagrant up with the specific provider +def vagrantUp(self, path): + self.log.debug(" Vagrant up:: Start") + self.log.debug("changing path to " + path) + os.chdir(path) + paramerters = pexpect.spawn("vagrant up --provider "+self.params.get('vagrant_PROVIDER')) + paramerters.expect('.*Would you like to register the system now.*', timeout=250) + paramerters.sendline("y") + paramerters.expect(".*username.*") + paramerters.sendline(self.params.get('vagrant_RHN_USERNAME')) + # paramerters.sendline("naverma@redhat.com") + paramerters.expect(".*password.*") + paramerters.sendline(self.params.get('vagrant_RHN_PASSWORD')) + # paramerters.sendline("*****") + paramerters.interact() + paramerters.close() + time.sleep(20) + out=global_status(self,path) + self.assertTrue( 'running' in out) + #self.log.debug(" Vagrant up:: Exit") + + return out + +#Returning Global status +def global_status(self, vm_name): + self.log.debug("Checking Global status ::Start") + self.log.info("vagrant global-status |grep " + vm_name + " |awk '{print $4}'") + p = subprocess.Popen("vagrant global-status |grep " + vm_name + " |awk '{print $4}'", stdout=subprocess.PIPE, + shell=True) + (output, err) = p.communicate() + self.log.debug(output) + #self.log.debug("Checking Global status ::Exit") + return output,err + + +def vagrantDestroy(self,path): + self.log.info(dash + " vagrant destroy ::Start" + dash) + os.chdir(path) + p = subprocess.Popen("vagrant destroy --force", stdout=subprocess.PIPE, shell=True) + (output, err) = p.communicate() + self.log.debug(output) + self.log.info('*******************8') + self.assertTrue('==> default: Destroying VM and associated drives' in output) + #self.log.info(dash + " vagrant destroy ::Exit" + dash) + return output,err + + +def vagrantSSH(self,command): + self.log.info(dash + "vagrant SSH :: Start" + dash) + p = subprocess.Popen("vagrant ssh -c "+command, stdout=subprocess.PIPE, shell=True) + (output, err) = p.communicate() + self.log.debug(output) + #self.log.info(dash + "vagrant SSH :: Exit" + dash) + return output + + +def vagrant_service_manager(self, path, command): + self.log.debug("vagrant_service_manager module inside Utils:: Start") + self.log.debug("changing path to " + path) + os.chdir(path) + p = subprocess.Popen("vagrant service-manager " + command) + (output, err) = p.communicate() + self.log.debug(output) + #self.log.debug("vagrant_service_manager module inside Utils:: Finish") + return output + + +def vagrant_box_add(self): + self.log.info("Vagrant Box add :: Start") + if os.path.isfile(self.params.get('vagrant_BOX_PATH')) ==True: + pass + p = subprocess.Popen('vagrant box add cdkv3 '+ str(self.params.get('vagrant_BOX_PATH'))) + (output, err) = p.communicate() + self.log.debug(output) + self.assertTrue('Successfully added box' in output) + + # self.log.info("Vagrant Box add ::Finish") + return output + +def vagrant_box_remove(self): + self.log.info("Vagrant Box Remove :: Start") + p = subprocess.Popen("vagrant box remove cdkv2 --force") + (output, err) = p.communicate() + self.assertTrue('Removing box' in output) + # self.log.info("Vagrant Box Remove ::Finish") + return output + +def vagrant_plugin_install(self): + try: + self.log.info("Vagrant Plugin Install :: Start") + os.chdir(self.params.get('vagrant_PLUGINS_DIR')) + #os.system("vagrant plugin install ./vagrant-registration-*.gem ./vagrant-service-manager-*.gem ./vagrant-sshfs-*.gem") + p = subprocess.Popen("vagrant plugin install ./vagrant-registration-*.gem ./vagrant-service-manager-*.gem ./vagrant-sshfs-*.gem") + (output, err) = p.communicate() + self.log.debug(output) + #return output + except: + self.log.info('Exception!') + #return output +# self.log.info("Vagrant Plugin Install ::Finish") + + + +# This method is for multi windows shell support ,it runs the specific commands in the particalar sheels +def shell_commands(self, command): + self.log.info("This method is used because we need to provide support for Powershell , cmd, cygwin, bash,ubuntu") + if self.params.get('Windows_Shell') == 'powershell': + operator = '|' + psxmlgen = subprocess.Popen([r'C:/WINDOWS/system32/WindowsPowerShell/v1.0/powershell.exe', + 'cd ' + self.params.get( + 'vagrant_VARGRANTFILE_DIRS') + 'misc/hyperv/rhel-k8s-singlenode-hyperv ' + operator + ' ' + command], + cwd=os.getcwd()) + result = psxmlgen.wait + time.sleep(20) + self.log.debug('Suspend result :' + str(result)) + elif self.params.get('Windows_Shell') == 'cmd': + operator = '&' + psxmlgen = subprocess.Popen([r'C:/Windows/System32/cmd.exe', + 'cd ' + self.params.get( + 'vagrant_VARGRANTFILE_DIRS') + 'misc/hyperv/rhel-k8s-singlenode-hyperv ' + operator + ' ' + command], + cwd=os.getcwd()) + result = psxmlgen.wait + time.sleep(20) + self.log.debug('Suspend result :' + str(result))