From 3fe5e8d6fb08ac4726356a93cec3025941734203 Mon Sep 17 00:00:00 2001 From: Timur Nurlygayanov Date: Mon, 4 Mar 2013 19:18:42 +0400 Subject: [PATCH] Added deployment script and automated tests. --- tests/deploy.sh | 83 ++++++++++++++++++++++++++++++ tests/selenium/conf.ini | 4 ++ tests/selenium/datacenters_page.py | 54 +++++++++++++++++++ tests/selenium/login_page.py | 29 +++++++++++ tests/selenium/services_page.py | 54 +++++++++++++++++++ tests/selenium/test.py | 34 ++++++++++++ 6 files changed, 258 insertions(+) create mode 100644 tests/deploy.sh create mode 100644 tests/selenium/conf.ini create mode 100644 tests/selenium/datacenters_page.py create mode 100644 tests/selenium/login_page.py create mode 100644 tests/selenium/services_page.py create mode 100644 tests/selenium/test.py diff --git a/tests/deploy.sh b/tests/deploy.sh new file mode 100644 index 0000000..d8732ff --- /dev/null +++ b/tests/deploy.sh @@ -0,0 +1,83 @@ +#!/usr/bin/expect -d +# The following directories should be created for this script: +# /opt/stack/devstack +# /opt/stack/keero +# the ssh key should be in directory /opt/stack/.ssh/ +# the iso file with windows should be in directory /opt/stack/ + +set timeout 1200 + +send_user "\n\nStart to login to the test bed...\n\n" + +spawn /usr/bin/ssh [lindex $argv 0]@[lindex $argv 1] +expect "password" +send -- "EVYiMCVZX9\n" +expect "*#*" + +send -- "su - stack\n" +expect "*$*" + +send -- "sudo killall python\n" +expect "*$*" +send -- "cd ~/devstack\n" +expect "*$*" +send -- "./unstack.sh\n" +expect "*$*" +send -- "./stack.sh\n" +expect "*Would you like to start it now?*" +send -- "y\n" +expect "*stack.sh completed*" + +send -- "source openrc admin admin\n" +expect "*$*" + +send -- "cd ~\n" +expect "*$*" + +send -- "nova keypair-add keero-linux-keys > heat_key.priv\n" +expect "*$*" + +send -- "glance image-create --name 'ws-2012-full-agent' --is-public true --container-format ovf --disk-format qcow2 < ws-2012-full-agent.qcow2\n" +expect "*$*" + +send -- "cd ~/keero\n" +expect "*$*" +send -- "git pull\n" +expect "/.ssh/id_rsa" +send -- "swordfish\n" +expect "*$*" +send -- "cp -Rf ~/keero/dashboard/windc /opt/stack/horizon/openstack_dashboard/dashboards/project\n" +expect "*$*" +send -- "cp -f ~/keero/dashboard/api/windc.py /opt/stack/horizon/openstack_dashboard/api/\n" +expect "*$*" +send -- "cp -Rf ~/keero/dashboard/windcclient /opt/stack/horizon/\n" +expect "*$*" +send -- "cd ~/keero/windc\n" +expect "*$*" +send -- "rm -rf windc.sqlite\n" +expect "*$*" +send -- "./tools/with_venv.sh ./bin/windc-api --config-file=./etc/windc-api-paste.ini --dbsync\n" +expect "*$*" +send -- "logout\n" +expect "*#*" + +send -- "rabbitmq-plugins enable rabbitmq_management\n" +expect "*#*" +send -- "service rabbitmq-server restart\n" +expect "*#*" +send -- "rabbitmqctl add_user keero keero\n" +expect "*#*" +send -- "rabbitmqctl set_user_tags keero administrator\n" +expect "*#*" + + +send -- "cd /opt/stack/devstack\n" +expect "*#*" +send -- "source openrc admin admin\n" +expect "*#*" +send -- "cd /opt/stack/keero/windc\n" +expect "*#*" +send -- "./tools/with_venv.sh ./bin/windc-api --config-file=./etc/windc-api-paste.ini &\n" +expect "*DEBUG Call factory*" +send -- "\n" +expect "*#*" diff --git a/tests/selenium/conf.ini b/tests/selenium/conf.ini new file mode 100644 index 0000000..8b43288 --- /dev/null +++ b/tests/selenium/conf.ini @@ -0,0 +1,4 @@ +[server] +address=http://172.18.124.101 +user=admin +password=AkvareL707 \ No newline at end of file diff --git a/tests/selenium/datacenters_page.py b/tests/selenium/datacenters_page.py new file mode 100644 index 0000000..b49c540 --- /dev/null +++ b/tests/selenium/datacenters_page.py @@ -0,0 +1,54 @@ +import re +from login_page import LoginPage + +class DataCentersPage(): + page = None + + def __init__(self): + start_page = LoginPage() + self.page = start_page.login() + self.page.find_element_by_link_text('Project').click() + self.page.find_element_by_link_text('Windows Data Centers').click() + + def create_data_center(self, name): + button_text = 'Create Windows Data Center' + self.page.find_element_by_link_text(button_text).click() + + name_field = self.page.find_element_by_id('id_name') + xpath = "//input[@value='Create']" + button = self.page.find_element_by_xpath(xpath) + + name_field.clear() + name_field.send_keys(name) + + button.click() + + return self.page + + def find_data_center(self, name): + return self.page.find_element_by_link_text(name) + + def delete_data_center(self, name): + datacenter = self.find_data_center(name) + link = datacenter.get_attribute('href') + datacenter_id = re.search('windc/(\S+)', link).group(0)[6:-1] + + xpath = ".//*[@id='windc__row__%s']/td[3]/div/a[2]" % datacenter_id + more_button = self.page.find_element_by_xpath(xpath) + + more_button.click() + + delete_button_id = "windc__row_%s__action_delete" % datacenter_id + delete_button = self.page.find_element_by_id(delete_button_id) + + delete_button.click() + + self.page.find_element_by_link_text("Delete Data Center").click() + + return self.page + + def select_data_center(self, name): + datacenter = self.page.find_data_center(name) + datacenter.click() + + return self.page diff --git a/tests/selenium/login_page.py b/tests/selenium/login_page.py new file mode 100644 index 0000000..ed62536 --- /dev/null +++ b/tests/selenium/login_page.py @@ -0,0 +1,29 @@ +import ConfigParser +from selenium import webdriver + +class LoginPage(): + + def login(self): + config = ConfigParser.RawConfigParser() + config.read('conf.ini') + url = config.get('server', 'address') + user = config.get('server', 'user') + password = config.get('server', 'password') + + page = webdriver.Firefox() + page.set_page_load_timeout(30) + page.implicitly_wait(30) + page.get(url) + name = page.find_element_by_name('username') + pwd = page.find_element_by_name('password') + xpath = "//button[@type='submit']" + button = page.find_element_by_xpath(xpath) + + name.clear() + name.send_keys(user) + pwd.clear() + pwd.send_keys(password) + + button.click() + + return page diff --git a/tests/selenium/services_page.py b/tests/selenium/services_page.py new file mode 100644 index 0000000..2f683b5 --- /dev/null +++ b/tests/selenium/services_page.py @@ -0,0 +1,54 @@ +import ConfigParser +from selenium import webdriver + +class ServicesPage(): + page = None + + def __init__(self, page): + self.page = page + + def create_service(self, service_type, parameters): + + button_id = 'services__action_CreateService' + button = self.page.find_element_by_id(button_id) + button.click() + + self.select_type_of_service(service_type) + + for parameter in parameters: + field = self.page.find_element_by_name(parameter.key) + field.clear() + field.send_keys(parameter.value) + + xpath = "//input[@value='Deploy']" + deploy_button = self.page.find_element_by_xpath(xpath) + deploy_button.click() + + return page + + def select_type_of_service(self, service_type): + tab = find_element_by_link_text(service_type) + tab.click() + return self.page + + def find_service(self, name): + return self.page.find_element_by_link_text(name) + + def delete_service(self, name): + service = self.find_data_center(name) + link = service.get_attribute('href') + + service_id = re.search('windc/(\S+)', link).group(0)[6:-1] + + xpath = ".//*[@id='services__row__%s']/td[5]/div/a[2]" % service_id + more_button = self.page.find_element_by_xpath(xpath) + more_button.click() + + delete_button_id = "services__row_%s__action_delete" % datacenter_id + delete_button = self.page.find_element_by_id(delete_button_id) + + delete_button.click() + + self.page.find_element_by_link_text("Delete Service").click() + + return self.page diff --git a/tests/selenium/test.py b/tests/selenium/test.py new file mode 100644 index 0000000..9fb0f3c --- /dev/null +++ b/tests/selenium/test.py @@ -0,0 +1,34 @@ +import untitests +from datacenters_page import DataCentersPage + +class SanityTests(): + + def setUp(self): + self.page = DataCentersPage() + + def tearDown(self): + self.page.close() + + def test_01_create_data_center(self): + self.page.create_data_center('dc1') + assert self.page.find_data_center('dc1') is not None + + def test_02_delete_data_center(self): + page.delete_data_center('dc1') + assert self.page.find_data_center('dc1') is None + + def test_03_create_data_centers(self): + for i in range(1,20): + name = 'datacenter' + str(i) + self.page.create_data_center(name) + assert self.page.find_data_center(name) is not None + + def test_04_delete_data_centers(self): + page.delete_data_center('datacenter1') + page.delete_data_center('datacenter20') + assert self.page.find_data_center('datacenter1') is None + assert self.page.find_data_center('datacenter20') is None + + for i in range(2,19): + name = 'datacenter' + str(i) + assert self.page.find_data_center(name) is not None