def initialize(self): self.log_info("Initializing") # General set-up common.env_setup() size = "medium" # Changing node profile and VIP flag if self.get_run_mode() == "DEV": common.change_node_profile("medium") common.add_gearsize_capability('medium') elif self.get_run_mode() == "OnPremise": size = "small" # Creating the application common.create_app( self.config.application_name, self.config.application_type, self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd, clone_repo = True, git_repo = "./" + self.config.application_name, gear_size = size ) # Embedding cartridges for cartridge in self.config.application_embedded_cartridges: common.embed( self.config.application_name, "add-" + cartridge, self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd )
def test_method(self): self.info("=====================") self.info("Creating a Jenkins application") self.info("=====================") common.create_app("jenkins", common.app_types["jenkins"], self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd, clone_repo = False) self.info("=====================") self.info("Creating an application") self.info("=====================") common.create_app(self.app_name, common.app_types[self.test_variant], self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd, clone_repo = False) if self.test_variant in ( "jbossas", "jbosseap" ): if self.config.options.run_mode=="DEV": common.change_node_profile("medium") self.info("=====================") self.info("Embedding Jenkins client") self.info("=====================") common.embed(self.app_name, "add-" + common.cartridge_types["jenkins"]) self.info("=====================") self.info("Checking Jenkins URLs") self.info("=====================") for url in ( OSConf.default.conf["apps"]["jenkins"]["url"], OSConf.default.conf["apps"][self.app_name]["embed"][common.cartridge_types["jenkins"]]["url"] ): ret_code = common.grep_web_page( url, [ "Authentication required", r"window.location.replace\('/login" ], "-L -k -H 'Pragma: no-cache'", 30, 5 ) self.assert_equal(ret_code, 0, "Login form must be shown") return self.passed("[US1941][runtime][rhc-cartridge]A user not logged in jenkins can not see the build and workspace existed in jenkins [P1]")
def test_method(self): self.info("===============================================") self.info("Creating a scalable application (PHP)") self.info("===============================================") common.create_app( "testapp", common.app_types['php'], self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd, clone_repo = False, scalable = True ) # Dependency self.info("===============================================") self.info("Creating a Jenkins app (It's a dependency)") self.info("===============================================") common.create_app( "jenkins", common.app_types['jenkins'], self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd, clone_repo = False ) for cartridge in common.cartridge_types.keys(): if cartridge == "mysql" or cartridge == "jenkins" or cartridge == "mongodb": expect_return_rest = "Added" expect_return_cli = 0 cartridge_enabled = True else: expect_return_rest = "Failed to add" expect_return_cli = 1 cartridge_enabled = False self.info("===============================================") self.info("Embedding cartridge via REST API - " + cartridge) self.info("===============================================") ( status, messages ) = self.config.rest_api.cartridge_add("testapp", common.cartridge_types[cartridge]) self.assert_true(messages[0]["text"].startswith(expect_return_rest)) # Dependency if cartridge_enabled: common.command_get_status("rhc cartridge remove %s -a %s -l %s -p '%s' --confirm %s" % (common.cartridge_types[cartridge], "testapp", self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd, common.RHTEST_RHC_CLIENT_OPTIONS)) self.info("===============================================") self.info("Embedding cartridge in the command line - " + cartridge) self.info("===============================================") ret_code = common.embed("testapp", "add-" + common.cartridge_types[cartridge]) self.assert_equal(ret_code, expect_return_cli) # Cleaning if cartridge_enabled: common.command_get_status("rhc cartridge remove %s -a %s -l %s -p '%s' --confirm %s" % (common.cartridge_types[cartridge], "testapp", self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd, common.RHTEST_RHC_CLIENT_OPTIONS)) # Everything is OK: Passed return self.passed(self.summary)
def test_method(self): # Create app ret = common.create_app(self.app_name, self.app_type, self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd, True, "./", self.scalable) self.assert_equal(ret, 0, "App creation failed") # Add hot_deploy marker ret = common.command_get_status("touch %s/.openshift/markers/hot_deploy" % (self.app_name)) self.assert_equal(ret, 0, "Failed to create hot_deploy marker") # Record the pids pid_lst1 = self.get_pids(self.app_name) print 'pid list: %s' % pid_lst1 self.assert_not_equal(len(pid_lst1), 0, "Failed to get pid") # Make some changes and git push self.str1 = 'Welcome to OpenShift' self.str2 = common.getRandomString() cmd = "sed -i -e 's/%s/%s/g' %s/%s" % (self.str1, self.str2, self.app_name, self.file_path[self.test_variant]) ret = common.command_get_status(cmd) self.assert_equal(ret, 0, "Failed to modify the app") # Git push all the changes (ret, output) = common.command_getstatusoutput("cd %s && git add . && git commit -amt && git push" % (self.app_name)) self.assert_equal(ret, 0, "Failed to git push") self.assert_not_match('Waiting for stop to finish', output, "'Waiting for stop to finish' shouldn't be found in the output") # Verify the changes ret = common.check_web_page_output(self.app_name, '', self.str2) self.assert_equal(ret, 0, "The changes doesn't take effect") # Get the pid and compare pid_lst2 = self.get_pids(self.app_name) print 'pid before git push: %s' % (pid_lst1) print 'pid after git push: %s' % (pid_lst2) self.assert_not_equal(len(pid_lst2), 0, "Failed to get pid") ret = self.compare_pid(pid_lst1, pid_lst2) self.assert_true(ret, 'PID changed after deploying') # Create jenkins server ret = common.create_app("jenkins", common.app_types['jenkins']) self.assert_equal(ret, 0, "Failed to create jenkins server") # Add jenkins-client to the app ret = common.embed(self.app_name, 'add-' + common.cartridge_types['jenkins']) self.assert_equal(ret, 0, "Failed to add jenkins-client to the app") # Make some changes self.str1 = self.str2 self.str2 = common.getRandomString() cmd = "sed -i -e 's/%s/%s/g' %s/%s" % (self.str1, self.str2, self.app_name, self.file_path[self.test_variant]) ret = common.command_get_status(cmd) self.assert_equal(ret, 0, "Failed to modify the app") # Git push all the changes ret = common.trigger_jenkins_build(self.app_name) self.assert_true(ret, "Failed to do jenkins build") # Verify the changes ret = common.check_web_page_output(self.app_name, '', self.str2) self.assert_equal(ret, 0, "The changes doesn't take effect") # Compare the pids pid_lst1 = pid_lst2 pid_lst2 = self.get_pids(self.app_name) print 'pid before git push: %s' % (pid_lst1) print 'pid after git push: %s' % (pid_lst2) self.assert_not_equal(len(pid_lst2), 0, "Failed to get pid") ret = self.compare_pid(pid_lst1, pid_lst2) self.assert_true(ret, 'PID changed after deploying') return self.passed()
def initialize(self): self.log_info("Initializing") common.env_setup() common.create_app( self.config.application_name, self.config.application_type, self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd, clone_repo = True, git_repo = self.config.git_repo, scalable = self.config.scalable )
def test_method(self): # Creation self.log_info('Creating application') common.create_app( self.application_name, common.app_types['jbosseap'], self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd) self.assert_equal(common.check_web_page_output(self.application_name), 0) # Deployment self.log_info('Modifying git repo') random_value = common.getRandomString() jsp_file = open(self.application_name + '/src/main/webapp/test.jsp', 'w') jsp_file.write(random_value) jsp_file.close() configuration_steps = [ 'cd %s' % self.application_name, 'git add .', 'git commit -a -m testing', 'git push' ] self.assert_equal(common.command_get_status(' && '.join(configuration_steps)), 0) self.assert_equal(common.check_web_page_output(self.application_name, 'test.jsp', random_value), 0) # Add MySQL self.log_info('Adding MySQL') common.embed(self.application_name, 'add-' + common.cartridge_types['mysql']) ( ret_code, ret_output ) = self.mysql_status() self.assert_true(ret_output.find('MySQL is running') != -1) # Remove MySQL self.log_info('Removing MySQL') common.embed(self.application_name, 'remove-' + common.cartridge_types['mysql']) ( ret_code, ret_output ) = self.mysql_status() self.assert_true(ret_output.find("%s" % (common.cartridge_types['mysql'])) != -1, "Failed to find given string in the output") # Remove the app self.log_info('Removing the app') ret_code = common.destroy_app(self.application_name) self.assert_equal(ret_code, 0) # Everythin is OK return self.passed(self.summary)
def create_apps_one_by_one(self, start, end): for i in range(start, end): app_name = "%s%s" %(self.app_name_prefix, i) self.info("Creating app#%d"%i) ret = common.create_app(app_name, self.app_type, self.user_email, self.user_passwd, False) self.assert_equal(0, ret, "App #%d must be created successfully"%i) return 0
def test_method(self): self.info("1. Create a %s application" %(self.app_type)) ret = common.create_app(self.app_name, self.app_type, self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd) self.assert_equal(ret, 0,"%s app should be created successfully" %(self.app_name)) file_name1 = "execute_risky_system_binaries.php" file_name2 = "execute_risky_system_binaries.sh" source_file1 = "%s/data/%s" %(WORK_DIR, file_name1) source_file2 = "%s/data/%s" %(WORK_DIR, file_name2) target_file1 = "%s/php/index.php" %(self.app_name) target_file2 = "%s/php/%s" %(self.app_name, file_name2) self.info("2. Copying test files to app git repo") ret = common.command_get_status("cp -f %s %s && cp -f %s %s" %(source_file1, target_file1, source_file2, target_file2)) self.assert_equal(ret, 0,"File and directories are added to your git repo successfully") self.info("3. Do git commit") ret = common.command_get_status("cd %s && git add . && git commit -m test && git push" %(self.app_name)) self.assert_equal(ret, 0, "File and directories are added to your git repo successfully") app_url = OSConf.get_app_url(self.app_name) self.info("4. Access app's URL to tigger test") ret = common.grep_web_page(app_url, "###RESULT###: PASS") self.assert_equal(ret, 0, "###RESULT###: PASS must be in %s"%app_url) return self.passed("%s passed" % self.__class__.__name__)
def test_method(self): ret = common.create_app(self.app_name, self.app_type, self.user_email, self.user_passwd, True, "./", self.scalable) self.assert_equal(ret, 0, "App creation failed") ret = common.embed(self.app_name, "add-" + common.cartridge_types["mysql"], self.user_email, self.user_passwd) self.assert_equal(ret, 0, "Failed to embed mysql to app") ret = self.prepare_jsp_file() self.assert_equal(ret, True, "Failed to prepare jsp file and mysql connector") ret = common.command_get_status("cd %s && git add . && git commit -amt && git push" % (self.app_name)) self.assert_equal(ret, 0, "Failed to git push") self.assert_equal(self.check_mysql_result(), 0, "Mysql doesn't work") if self.scalable: ret = common.scale_up(self.app_name) self.assert_equal(ret, 0, "Failed to scale up app") self.assert_equal(self.check_mysql_result(), 0, "Mysql doesn't work after scale up") ret = common.scale_down(self.app_name) self.assert_equal(ret, 0, "Failed to scale down app") self.assert_equal(self.check_mysql_result(), 0, "Mysql doesn't work after scale down") ret = common.embed(self.app_name, "remove-" + common.cartridge_types["mysql"]) self.assert_equal(ret, 0, "Failed to remove mysql-5.1 from app") return self.passed("%s passed" % self.__class__.__name__)
def enable_jenkins(self): self.log_info("Enabling Jenkins if it's necessary") if self.config.jenkins_is_needed: common.create_app( "jenkins", common.app_types['jenkins'], self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd, clone_repo = False ) common.embed( self.config.application_name, "add-" + common.cartridge_types["jenkins"], self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd )
def test_method(self): self.info("Create a %s application" %(self.app_type)) ret = common.create_app(self.app_name, self.app_type, self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd) self.assert_equal(ret, 0, "App should be created successfully") source_file = "%s/data/qpid_fuzzing_stage.php" %(WORK_DIR) target_file = "%s/php/index.php" %(self.app_name) self.info("2.Copying test files to app git repo") ret = common.command_get_status("cp -f %s %s" %(source_file, target_file)) self.assert_equal(ret, 0) self.info("3. Do git commit") ret = common.command_get_status("cd %s && git add . && git commit -m test && git push" %(self.app_name)) self.assert_equal(ret, 0, "File and directories are added to your git repo successfully") self.info("4. Get app url") app_url = OSConf.get_app_url(self.app_name) self.info("Access app's URL to tigger test") ret = common.grep_web_page("%s/index.php?action=create"%app_url, "###RESULT###: PASS") self.assert_equal(ret, 0) return self.passed("%s passed" % self.__class__.__name__)
def test_method(self): self.info("===============================") self.info("1. Changing MIN_GEAR settings in the cartridge descriptor file") self.info("===============================") status = self.change_descriptor(3) self.assert_equal(status, 0, "Error during manipulating with manifest.yml") # Wait for rhc-broker to start time.sleep(15) self.info("===============================") self.info("2. Creating a scalable application") self.info("===============================") status = common.create_app(self.app_name, common.app_types[self.app_type], scalable = True, clone_repo = False, timeout=360) self.assert_equal(status, 0, "Unable to create an app") self.info("===============================") self.info("3. Checking the number of gears") self.info("===============================") ( gear_info, gear_count ) = self.config.rest_api.get_gears(self.app_name) self.assert_equal(gear_count, 4, "Gear count must be 4") self.info("===============================") self.info("4. Scaling down") self.info("===============================") (status, resp) = self.config.rest_api.app_scale_down(self.app_name) self.assert_match(status, 'Unprocessable Entity', "Scale-down operation must fail") # Everything is OK return self.passed(self.summary)
def test_method(self): self.info("1. Create an observer app") ret = common.create_app(self.app_name, common.app_types[self.app_type], self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd, True) self.assert_equal(ret,0, "App should be created") self.info("2. Modify the observer %s"%self.app_name) ret = common.command_get_status(''' cd %s && cat <<EOF >wsgi/application && %s EOF git commit -m "Changed APP" -a && git push '''%(self.app_name, ObserverGenerator.get_application())) self.assert_equal(ret,0, "App should be created") for app_t in ('php', 'python', 'perl', 'rack'): self.app_name2 = "%s%s"%(self.app_name,app_t) self.info("3x. Create target App %s"%self.app_name2) ret = common.create_app(self.app_name2, common.app_types[app_t], self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd, False) self.assert_equal(ret,0, "Second application should be deployed.") self.info("4x. Verify http connection to %s"%self.app_name2) self.verify(self.app_name, self.app_name2, [('return',113)]) self.assert_equal(ret,0, "It should not be allowed to connect from %s->%s"%(self.app_name, self.app_name2)) self.info("5x. Delete it") ret = common.destroy_app(self.app_name2, self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd) self.assert_equal(ret,0, "App should be destroyed") self.info("6x. Verify self") self.verify(self.app_name, self.app_name, [('return',0)]) self.assert_equal(ret,0, "App should be verified") return self.passed("%s passed" % self.__class__.__name__)
def test_method(self): self.info("1. Create a %s application" %(self.app_type)) ret = common.create_app(self.app_name1, self.app_type, self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd) self.assert_equal(0, ret, "App#1 should be created successfully") self.info("2. Copying test files to app git repo") ret = common.command_get_status("cp -f %s %s" %(self.source_file, self.target_file1)) self.assert_equal(0, ret) self.info("3. Do git commit") ret = common.command_get_status("cd %s && git add . && git commit -m test && git push" %(self.app_name1)) self.assert_equal(0, ret, "File and directories are added to your git repo successfully") app_url = OSConf.get_app_url(self.app_name1) self.info("4. Access app's URL to create files in tmp directory") ret = common.grep_web_page("%s/%s" %(app_url, self.url_path1), ["RESULT=0"]) self.assert_equal(0, ret, "RESULT=0 should be seen in output of %s"%app_url) self.info("5. Create another %s application" %(self.app_type)) ret = common.create_app(self.app_name2, self.app_type, self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd) self.assert_equal(0, ret, "App#2 should be created successfully") self.info("6. Copying test files to app git repo") common.command_get_status("cp -f %s %s" %(self.source_file, self.target_file2)) self.assert_equal(0, ret, "Copy should be done.") self.info("7. Do git commit") ret = common.command_get_status("cd %s && git add . && git commit -m test && git push" %(self.app_name2)) self.assert_equal(0, ret, "File and directories are added to your git repo successfully") self.info("8. Get app url") app_url = OSConf.get_app_url(self.app_name2) self.info("9. Access app's URL to check files in tmp directory") common.grep_web_page("%s/%s" %(app_url, self.url_path2), ["RESULT=1", "No such file or directory"]) self.assert_equal(ret, 0,"Files is created in tmp directory") return self.passed("%s passed" % self.__class__.__name__)
def test_method(self): self.step("Create %s app: %s" % (self.app_type, self.app_name)) ret = common.create_app(self.app_name, self.app_type, self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd, scalable=self.scalable, disable_autoscaling=False) self.assert_equal(ret, 0, "Failed to create %s app: %s" % (self.app_type, self.app_name)) self.step("Add databases to the app") ret = common.embed(self.app_name, "add-" + common.cartridge_types["mysql"], self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd) self.assert_equal(ret, 0, "Failed to add mysql") ret = common.embed(self.app_name, "add-" + common.cartridge_types["postgresql"], self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd) self.assert_equal(ret, 0, "Failed to add postgresql") #ret = common.embed(self.app_name, "add-" + common.cartridge_types["mongodb"], self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd) #self.assert_equal(ret, 0, "Failed to add mongodb") self.step("Applications must be accessed by their URL before you can take a thread dump") app_url = OSConf.get_app_url(self.app_name) cmd = "curl %s" %(app_url) (ret, output) = common.command_getstatusoutput(cmd) self.assert_equal(ret, 0, "Fail to access app") self.step("Generate threaddump file") cmd = "rhc threaddump %s -l %s -p '%s' %s" % ( self.app_name, self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd, common.RHTEST_RHC_CLIENT_OPTIONS) (ret, output) = common.command_getstatusoutput(cmd) self.assert_equal(ret, 0, "Failed to generate threaddump file for %s app: %s" % (self.app_type, self.app_name)) self.debug("OUTPUT: %s" % output) match = re.search(r'(?<=The thread dump file will be available via: ).*$', output, re.M) #match = re.search(r'(?<=rhc tail %s )-f \S+' % (self.app_name), output) self.assert_not_equal(match, None, "Failed to find command to see the threaddump file") self.step("Check the threaddump file") #tail_cmd = "rhc tail %s " % (self.app_name) + match.group(0) + " -l %s -p '%s'" % (self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd) tail_cmd = match.group(0) + " -l %s -p '%s'" % (self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd) print "Command: %s" % (tail_cmd) self.child = pexpect.spawn(tail_cmd) time.sleep(10) match_num = 0.0 for s in self.str_list: try: # increase the timeout from 3 to 10 self.child.expect(s, timeout=20) match_num += 1 except pexpect.TIMEOUT: pass rate = match_num/len(self.str_list) if rate >= self.match_rate: self.info("Successfully matched %d%% strings in the list" % (int(rate*100))) return self.passed() else: self.info("Only matched %d%% strings in the list. The lowest match rate is %f%%" % (int(rate*100), int(self.match_rate*100))) return self.failed()
def create_apps_one_by_one(self, start, end): for i in range(start, end + 1): app_name = "%s%s" %(self.app_name_prefix, i) ret = common.create_app(app_name, self.app_type, self.user_email, self.user_passwd) if ret != 0: print "---BAD---" break return ret
def test_method(self): ret = common.create_app(self.app_name, common.app_types["python"]) self.assert_equal(ret, 0, "The app should be created.") self.info("Check the process SELinux context") ret = self.check_proc_context() self.assert_equal(ret, 0) return self.passed("%s passed" % self.__class__.__name__)
def test_method(self): self.info("=" * 80) self.info("Creating a PHP application") self.info("=" * 80) common.create_app(self.application_name, self.application_type, clone_repo = False) self.info("=" * 80) self.info("Embedding MongoDB cartridge") self.info("=" * 80) common.embed(self.application_name, "add-" + common.cartridge_types["mongodb"]) self.info("=" * 80) self.info("Checking the version of MongoDB") self.info("=" * 80) ( ret_code, ret_output ) = common.run_remote_cmd(self.application_name, "eval $(cat mongodb-2.2/pid/mongodb.pid | xargs -I{} ps -p {} -o cmd= | cut -d' ' -f1) --version") self.assert_true(ret_output.find("db version v2.2") != -1, "MongoDB version must be in branch 2.2") # everything is OK return self.passed(self.summary)
def create_app(self, *args, **kwargs): if kwargs.has_key("some_argument"): print "Possible argument received: ", kwargs['some_argument'] if kwargs.has_key("app_name"): print "Another argument received: ", kwargs['app_name'] self.app_name=kwargs['app_name'] return common.create_app(self.app_name, common.app_types[self.app_type], self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd, True)
def test_method(self): self.log_info('Creating an application') common.create_app( self.application_name, self.application_type, self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd, clone_repo = False ) self.log_info("Running command 'quota'") ( ret_code, ret_output ) = common.run_remote_cmd(self.application_name, 'quota') self.info('Asserting that the return code of the command is 0...') self.assert_equal(ret_code, 0) self.info('Verifyting the correct output...') uuid = OSConf.get_app_uuid(self.application_name) match = re.match('Disk quotas for user %s' % uuid, ret_output) self.assert_true(match != None) # Everything is OK self.passed(self.summary)
def test_method(self): msetup = common.setup_multi_node_env(self.district_name) self.assert_true((len(msetup['nodes'])>=2), "Missing multi node environment!") self.info("Found %s connected nodes"%len(msetup['nodes'])) ret = common.set_max_gears(self.user_email, common.DEV_MAX_GEARS) #self.assert_equal(ret, 0, "Unable set max_gears") if self.scalable: ret = common.create_scalable_app(self.app_name, self.app_type, clone_repo=False) else: ret = common.create_app(self.app_name, self.app_type, clone_repo=False) self.assert_equal(ret, 0, "Unable to create the app") ret = common.embed(self.app_name, 'add-%s'%self.cart_type) self.assert_equal(ret, 0, "Unable to embed the app by %s"%self.db_variant) #app_uuid=OSConf.get_app_uuid(self.app_name) app_url=OSConf.get_app_url(self.app_name) #node (gear_groups, gear_count) = self.config.rest_api.get_gears(self.app_name) gear_to_move = None for gear_group in gear_groups: for cart in gear_group['cartridges']: if cart['name'].find('%s' % self.db_variant) != -1: gear_to_move = gear_group['gears'][0]['id'] self.assert_true((gear_to_move is not None), "Unable to find gear of %s"%self.db_variant) self.info("Gear of %s"%gear_to_move) district_of_moved_gear = common.get_district_of_gear(gear_to_move) node_of_moved_gear = common.get_node_of_gear(gear_to_move) self.assert_true((node_of_moved_gear is not None), "Unable to find server_identity per gear[%s]"%gear_to_move) self.info("Finding available nodes for possible move gear[%s] within district[%s]"%(gear_to_move, district_of_moved_gear)) node_to_move = None for n in common.get_nodes_of_district(district_of_moved_gear): if n == node_of_moved_gear: continue else: node_to_move = n break app_url_private_ip = common.get_private_ip(app_url) self.info("app[%s] -> node[%s]"%(app_url,app_url_private_ip)) self.info("Node to move: %s"%node_to_move) if node_to_move: ret = common.move_gear_between_nodes(gear_to_move, node_to_move) self.assert_equal(ret, 0, "Unable to move gear.") else: return self.abort("Unable to find a free node to move in withing district[%s]."%district_of_moved_gear) return self.passed("%s passed" % self.__class__.__name__)
def test_method(self): # Create app ret = common.create_app(self.app_name, self.app_type, self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd) self.assert_equal(ret, 0, "App creation failed") # Add an public git repo as a submodule of the app cmd = "cd %s && git submodule add %s" % (self.git_repo, self.submodule_repo) (ret, output) = common.command_getstatusoutput(cmd) self.debug(output) self.assert_equal(ret, 0, "Failed to add submodule") # Modify .openshift/action_hooks/pre_build try: f = file("%s/.openshift/action_hooks/pre_build" % (self.git_repo), "w") f.write(GitSubmoduleTest.CODE) f.close() except IOError: return self.failed("Failed to write code to %s/.openshift/action_hooks/pre_build" % (self.git_repo)) except: self.error("Unknown error") import traceback traceback.print_exc() return self.failed("%s failed" % self.__class__.__name__) # Git push all the changes cmd = "cd %s && git add . && git commit -amt && git push" % (self.git_repo) ###expected_output = "Test Result: PASS. git submodule update is executed successfully on server" (ret, output) = common.command_getstatusoutput(cmd) self.debug(output) self.assert_equal(ret, 0, "Git push failed") ###if output.find(expected_output) == -1: ### return self.failed("%s failed" % self.__class__.__name__) # Git clone the app's repo and pull down the submodule cmd = "git clone %s %s-clone && cd %s-clone && git submodule init && git submodule update" % (OSConf.get_git_url(self.app_name), self.app_name, self.app_name) (ret, output) = common.command_getstatusoutput(cmd) self.debug(output) self.assert_equal(ret, 0, "Failed to git clone the repo and pull down submodule") # Check if the submodule is pulled down self.info("Checking dir: %s-clone/%s" % (self.app_name, self.submodule_name)) try: lst = os.listdir("%s-clone/%s" % (self.app_name, self.submodule_name)) except OSError: return self.failed("Failed to list files under %s-clone/%s. The dir may not exist" % (self.git_repo, self.submodule_name)) except: self.error("Unknown error") import traceback traceback.print_exc() return self.failed("%s failed" % self.__class__.__name__) if len(lst) == 0: return self.failed("The git submodule isn't pulled down") else: self.info("The git submodule is successfully pulled down") return self.passed("%s passed" % self.__class__.__name__)
def initialize(self): self.log_info("Initializing") self.config.application_name = common.getRandomString() # General set-up common.env_setup() # Creating the application common.create_app( self.config.application_name, self.config.application_type, self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd, clone_repo = True, git_repo = "./" + self.config.application_name ) # Embedding cartridges for cartridge in self.config.application_embedded_cartridges: common.embed( self.config.application_name, "add-" + cartridge, self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd )
def test_method(self): #"Create a diy app", ret = common.create_app(self.app_name, self.app_type, self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd) self.assert_equal(ret,0, "the app should be created successfully") #"Embed mysql to the app", ret = common.embed(self.app_name, "add-" + common.cartridge_types["mysql"]) self.assert_equal(ret, 0, "the mysql cartridge should be embedded successfully") #"Remove embedded mysql from the app", ret = common.embed(self.app_name, "remove-" + common.cartridge_types["mysql"]) self.assert_equal(ret,0, "the mysql should be removed successfully") return self.passed("%s passed" % self.__class__.__name__)
def test_method(self): # Create app ret = common.create_app(self.app_name, self.app_type, self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd, True, "./", self.scalable) self.assert_equal(ret, 0, "App creation failed") # Add postgresql-9.2 to the app ret = common.embed(self.app_name, 'add-' + common.cartridge_types['postgresql-9.2']) self.assert_equal(ret, 0, "Failed to add Postgresql-9.2 to the app") #Check the version of cartridge cmd = "ssh %s 'psql --version | grep psql '" % (OSConf.get_ssh_url(self.app_name)) (status, output) = common.command_getstatusoutput(cmd) self.assert_equal(status, 0, "Check Version Failed") #Scale up if self.scalable: ret = common.scale_up(self.app_name) self.assert_equal(0, ret, "Unable to scale_up.") #Stop cmd = "rhc cartridge stop %s -a %s -l %s -p '%s' %s" %(common.cartridge_types['postgresql-9.2'], self.app_name, self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd, common.RHTEST_RHC_CLIENT_OPTIONS) (status, output) = common.command_getstatusoutput(cmd) self.assert_equal(status, 0, "Stop failed") #Start cmd = "rhc cartridge start %s -a %s -l %s -p '%s' %s" %(common.cartridge_types['postgresql-9.2'], self.app_name, self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd, common.RHTEST_RHC_CLIENT_OPTIONS) (status, output) = common.command_getstatusoutput(cmd) self.assert_equal(status, 0, "Start failed") #Restart cmd = "rhc cartridge restart %s -a %s -l %s -p '%s' %s" %(common.cartridge_types['postgresql-9.2'], self.app_name, self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd, common.RHTEST_RHC_CLIENT_OPTIONS) (status, output) = common.command_getstatusoutput(cmd) self.assert_equal(status, 0, "Restart failed") #Reload cmd = "rhc cartridge reload %s -a %s -l %s -p '%s' %s" %(common.cartridge_types['postgresql-9.2'], self.app_name, self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd, common.RHTEST_RHC_CLIENT_OPTIONS) (status, output) = common.command_getstatusoutput(cmd) self.assert_equal(status, 0, "Reload failed") #Status cmd = "rhc cartridge status %s -a %s -l %s -p '%s' %s" %(common.cartridge_types['postgresql-9.2'], self.app_name, self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd, common.RHTEST_RHC_CLIENT_OPTIONS) (status, output) = common.command_getstatusoutput(cmd) self.assert_equal(status, 0, "Show status failed") #Remove cmd = "rhc cartridge remove %s -a %s -l %s -p '%s' %s --confirm" %(common.cartridge_types['postgresql-9.2'], self.app_name, self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd, common.RHTEST_RHC_CLIENT_OPTIONS) (status, output) = common.command_getstatusoutput(cmd) self.assert_equal(status, 0, "Remove failed") return self.passed()
def initialize(self): self.log_info("Initializing...") common.env_setup() # Creating the application self.app_type = self.config.application_type self.app_name = self.config.application_name common.create_app( self.config.application_name, self.config.application_type, self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd, clone_repo = True, git_repo = "./" + self.config.application_name, scalable = self.config.scalable ) # Checking the application URL status, res = self.config.rest_api.app_get(self.config.application_name) if status == 'OK': self.config.application_url = res['app_url'] else: self.config.applicaton_url = 'Not found' self.info("Application URL: " + self.config.application_url)
def test_method(self): # 1.Create an app self.info("Create a %s application" %(self.app_type)) ret = common.create_app(self.app_name, self.app_type, self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd, False) self.assert_equal(ret, 0, "App should be created successfully") # 2. Scan files self.info("Check file context") ret=self.check_file_context() self.assert_equal(ret, 0) return self.passed("%s passed" % self.__class__.__name__)
def test_method(self): # Create app ret = common.create_app(self.app_name, self.app_type, self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd) self.assert_equal(ret, 0, "App creation failed") # Try to embed phpmyadmin without mysql embedded ret = common.embed(self.app_name, "add-" + common.cartridge_types["phpmyadmin"], self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd) self.assert_not_equal(ret, 0, "phpmyadmin shouldn't be embedded before embedding mysql") # Embed mysql to it ret = common.embed(self.app_name, "add-" + common.cartridge_types["mysql"], self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd) self.assert_equal(ret, 0, "Failed to embed mysql to the app") # Embed phpmyadmin to it ret = common.embed(self.app_name, "add-" + common.cartridge_types["phpmyadmin"], self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd) self.assert_equal(ret, 0, "Failed to embed MySQL Admin(phpmyadmin) to the app") # Check phpmyadmin is working properly mysql_username = OSConf.default.conf['apps'][self.app_name]['embed'][common.cartridge_types["mysql"]]['username'] mysql_passwd = OSConf.default.conf['apps'][self.app_name]['embed'][common.cartridge_types["mysql"]]['password'] phpadmin_url = OSConf.default.conf['apps'][self.app_name]['embed'][common.cartridge_types["phpmyadmin"]]['url'] expected_output = "www.phpMyAdmin.net" ret = common.grep_web_page(phpadmin_url, common.raw_str(expected_output), "-k -H 'Pragma: no-cache' -L -u '%s:%s'" % (mysql_username, mysql_passwd), 5, 4) self.assert_equal(ret, 0, "phpmyadmin isn't working properly") # Remove embedded mysql from the app ret = common.embed(self.app_name, "remove-" + common.cartridge_types["mysql"], self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd) self.assert_equal(ret, 0, "Failed to remove embedded mysql from the app") # Check phpmyadmin isn't removed time.sleep(5) cmd = "curl -k -H 'Pragma: no-cache' -L -u '%s:%s' %s" % (mysql_username, mysql_passwd, phpadmin_url) (ret, output) = common.command_getstatusoutput(cmd, quiet=True) self.assert_not_match("404 Not Found", output, "Found '404 Not Found'. phpmyadmin shouldn't be removed") # Check mysql database is inaccessable expected_outputs = [common.raw_str("phpMyAdmin - Error"), common.raw_str("#2003 - Can't connect to MySQL server on"), common.raw_str("The server is not responding")] ret = common.grep_web_page(phpadmin_url, expected_outputs, "-k -H 'Pragma: no-cache' -L -u '%s:%s'" % (mysql_username, mysql_passwd), 5, 4, True) self.assert_equal(ret, 0, "phpmyadmin shouldn't be working!!!") # Re-embed mysql to the app ret = common.embed(self.app_name, "add-" + common.cartridge_types["mysql"], self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd) self.assert_equal(ret, 0, "Failed to re-embed mysql") # Check phpmyadmin is working properly again mysql_username = OSConf.default.conf['apps'][self.app_name]['embed'][common.cartridge_types["mysql"]]['username'] mysql_passwd = OSConf.default.conf['apps'][self.app_name]['embed'][common.cartridge_types["mysql"]]['password'] ret = common.grep_web_page(phpadmin_url, common.raw_str(expected_output), "-k -H 'Pragma: no-cache' -L -u '%s:%s'" % (mysql_username, mysql_passwd), 5, 4) expected_output = "www.phpMyAdmin.net" self.assert_equal(ret, 0, "phpmyadmin isn't working properly after re-embedding mysql") # The end return self.passed("%s passed" % self.__class__.__name__)
def test_method(self): # Create app ret = common.create_app(self.app_name, self.app_type, self.config.OPENSHIFT_user_email, self.config.OPENSHIFT_user_passwd) self.assert_equal(ret, 0, "App creation failed") # Add postgresql to app ret = common.embed(self.app_name, "add-" + common.cartridge_types["postgresql-9.2"]) self.assert_equal(ret, 0, "Failed to add postgresql to app") #Trigger env reload ret = common.trigger_env_reload(self.git_repo) self.assert_equal(ret, True, "Failed to trigger env reload") #Check env vars ret = self.check_app(self.app_name, self.cart, common.type_to_cart(common.cartridge_types["postgresql-9.2"])) self.assert_equal(ret, True, "postgresql env var check failed") return self.passed("%s passed" % self.__class__.__name__)
def test_method(self): #"Create an %s app: %s" % (self.app_type, self.app_name), ret = common.create_app(self.app_name, self.app_type) self.assert_equal(ret, 0, "App should be created successfully") #"Copy template files", ret = common.command_get_status("cp -f %s/data/illegal_app_content/* %s/wsgi/" % (self.mydir, self.app_name)) self.assert_equal(ret, 0) #"Git push codes", ret = common.command_get_status("cd %s/wsgi/ && git add . && git commit -am 'update app' && git push" % self.app_name) self.assert_equal(ret, 0) #"Get app URL", app_url = common.get_app_url_from_user_info(self.app_name) #"Check feedback", ret = common.grep_web_page(app_url, 'RETURN VALUE:0') self.assert_equal(ret, 1) #the string shouldn't be there return self.passed("%s passed" % self.__class__.__name__)
import os import unittest from common import create_app app = create_app(os.getenv('APP_ENV')) @app.cli.command() def test(): """Runs the tests without code coverage.""" tests = unittest.TestLoader().discover('tests', pattern='test*.py') result = unittest.TextTestRunner(verbosity=2).run(tests) if result.wasSuccessful(): return 0 return 1
def setup(self): self.app = create_app() auth.init_app(self.app)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from flask import render_template from common import create_app, register_bps, register_exts import config app = create_app(config, __name__) register_bps(app) register_exts(app) app.add_url_rule('/', endpoint='index', view_func=lambda: render_template('index.html')) if __name__ == '__main__': app.run()
def setUp(self): app = create_app() self.app = app self.client = app.test_client()
#! /usr/bin/env python # -*- coding: utf-8 -*- # vim:fenc=utf-8 # # Copyright © 2019 pavle <*****@*****.**> # # Distributed under terms of the BSD-3-Clause license. from app import create_blueprint as app_blueprint from common import create_app app = create_app() app.register_blueprint(app_blueprint(), url_prefix='/api')