Fuego-Release-Test fixes
cover Fuego-Release-Test fixes
Hello, everyone.
This series of patches implements Tim's suggestions on top of the original patches that have been sent last week and integrated into fuego-core/master.
Thanks
--
Guilherme
Guilherme Campos Camargo (8):
Rename Functional.fuegotest to Functional.fuego_release_test Add underscores to variables in spec.json
Add specs for 'test' and 'next' branches
Replace single-quote with double-quotes on long strings Use '+' on long wrapped strings to show contatenation explicitly Avoid reordering conditional logic to improve readability Keep the output of the test in TAP format
Use atexit to remove the docker container after the test
.../Functional.fuego_release_test/fuego_test.sh | 35 +++++
.../tests/Functional.fuego_release_test/spec.json | 23 ++++
.../test_run.py | 146 +++++++++++----------
engine/tests/Functional.fuegotest/fuego_test.sh | 36 -----
engine/tests/Functional.fuegotest/spec.json | 11 --
5 files changed, 136 insertions(+), 115 deletions(-)
create mode 100755 engine/tests/Functional.fuego_release_test/fuego_test.sh
create mode 100644 engine/tests/Functional.fuego_release_test/spec.json
rename engine/tests/{Functional.fuegotest => Functional.fuego_release_test}/test_run.py (78%)
delete mode 100755 engine/tests/Functional.fuegotest/fuego_test.sh
delete mode 100644 engine/tests/Functional.fuegotest/spec.jsonSignature · 1 line
2.16.3
PATCH 1/8 Rename Functional.fuegotest to Functional.fuego_release_test
Replace fuegotest with fuego_release_test in order to fit other Fuego-related tests better.
---
.../fuego_test.sh | 12 ++++++------
.../spec.json | 2 +-
.../test_run.py | 0
3 files changed, 7 insertions(+), 7 deletions(-)
rename engine/tests/{Functional.fuegotest => Functional.fuego_release_test}/fuego_test.sh (60%)
rename engine/tests/{Functional.fuegotest => Functional.fuego_release_test}/spec.json (84%)
rename engine/tests/{Functional.fuegotest => Functional.fuego_release_test}/test_run.py (100%)engine/tests/Functional.fuego_release_test/fuego_test.sh renamed from engine/tests/Functional.fuegotest/fuego_test.sh +6 -6
@@ -7,17 +7,17 @@ function test_build { rm -r ${fuego_release_dir} fi echo "Cloning fuego from \ - ${FUNCTIONAL_FUEGOTEST_FUEGOREPO}:${FUNCTIONAL_FUEGOTEST_FUEGOBRANCH}" + ${FUNCTIONAL_FUEGO_RELEASE_TEST_FUEGOREPO}:${FUNCTIONAL_FUEGO_RELEASE_TEST_FUEGOBRANCH}" git clone --depth 1 --single-branch \ - --branch "${FUNCTIONAL_FUEGOTEST_FUEGOBRANCH}" \ - "${FUNCTIONAL_FUEGOTEST_FUEGOREPO}" \ + --branch "${FUNCTIONAL_FUEGO_RELEASE_TEST_FUEGOBRANCH}" \ + "${FUNCTIONAL_FUEGO_RELEASE_TEST_FUEGOREPO}" \ "${fuego_release_dir}/fuego" echo "Cloning fuego-core from \ - ${FUNCTIONAL_FUEGOTEST_FUEGOCOREREPO}:${FUNCTIONAL_FUEGOTEST_FUEGOCOREBRANCH}" + ${FUNCTIONAL_FUEGO_RELEASE_TEST_FUEGOCOREREPO}:${FUNCTIONAL_FUEGO_RELEASE_TEST_FUEGOCOREBRANCH}" git clone --depth 1 --single-branch \ - --branch "${FUNCTIONAL_FUEGOTEST_FUEGOCOREBRANCH}" \ - "${FUNCTIONAL_FUEGOTEST_FUEGOCOREREPO}" \ + --branch "${FUNCTIONAL_FUEGO_RELEASE_TEST_FUEGOCOREBRANCH}" \ + "${FUNCTIONAL_FUEGO_RELEASE_TEST_FUEGOCOREREPO}" \ "${fuego_release_dir}/fuego-core" cd - }
engine/tests/Functional.fuego_release_test/spec.json renamed from engine/tests/Functional.fuegotest/spec.json +1 -1
@@ -1,5 +1,5 @@ { - "testName": "Functional.fuegotest", + "testName": "Functional.fuego_release_test", "specs": { "default": { "FUEGOREPO":"https://bitbucket.org/tbird20d/fuego",
engine/tests/Functional.fuego_release_test/test_run.py renamed from engine/tests/Functional.fuegotest/test_run.py +0 -0
Signature · 1 line
2.16.3
PATCH 2/8 Add underscores to variables in spec.json
In reply to Guilherme Campos CamargoAdd underscores to improve readability. Also reassign their names to local variables on the shell script to reduce the name sizes on the script.
--- .../Functional.fuego_release_test/fuego_test.sh | 23 +++++++++++----------- .../tests/Functional.fuego_release_test/spec.json | 8 ++++---- 2 files changed, 15 insertions(+), 16 deletions(-)
engine/tests/Functional.fuego_release_test/fuego_test.sh +11 -12
@@ -2,23 +2,22 @@ readonly fuego_release_dir=fuego-release +readonly fuego_repo="${FUNCTIONAL_FUEGO_RELEASE_TEST_FUEGO_REPO}" +readonly fuego_branch="${FUNCTIONAL_FUEGO_RELEASE_TEST_FUEGO_BRANCH}" +readonly fuego_core_repo="${FUNCTIONAL_FUEGO_RELEASE_TEST_FUEGO_CORE_REPO}" +readonly fuego_core_branch="${FUNCTIONAL_FUEGO_RELEASE_TEST_FUEGO_CORE_BRANCH}" + function test_build { if [ -d ${fuego_release_dir} ]; then rm -r ${fuego_release_dir} fi - echo "Cloning fuego from \ - ${FUNCTIONAL_FUEGO_RELEASE_TEST_FUEGOREPO}:${FUNCTIONAL_FUEGO_RELEASE_TEST_FUEGOBRANCH}" - git clone --depth 1 --single-branch \ - --branch "${FUNCTIONAL_FUEGO_RELEASE_TEST_FUEGOBRANCH}" \ - "${FUNCTIONAL_FUEGO_RELEASE_TEST_FUEGOREPO}" \ - "${fuego_release_dir}/fuego" + echo "Cloning fuego from ${fuego_repo}:${fuego_branch}" + git clone --depth 1 --single-branch --branch "${fuego_branch}" \ + "${fuego_repo}" "${fuego_release_dir}/fuego" - echo "Cloning fuego-core from \ - ${FUNCTIONAL_FUEGO_RELEASE_TEST_FUEGOCOREREPO}:${FUNCTIONAL_FUEGO_RELEASE_TEST_FUEGOCOREBRANCH}" - git clone --depth 1 --single-branch \ - --branch "${FUNCTIONAL_FUEGO_RELEASE_TEST_FUEGOCOREBRANCH}" \ - "${FUNCTIONAL_FUEGO_RELEASE_TEST_FUEGOCOREREPO}" \ - "${fuego_release_dir}/fuego-core" + echo "Cloning fuego-core from ${fuego_core_repo}:${fuego_core_branch}" + git clone --depth 1 --single-branch --branch "${fuego_core_branch}" \ + "${fuego_core_repo}" "${fuego_release_dir}/fuego-core" cd - }
engine/tests/Functional.fuego_release_test/spec.json +4 -4
@@ -2,10 +2,10 @@ "testName": "Functional.fuego_release_test", "specs": { "default": { - "FUEGOREPO":"https://bitbucket.org/tbird20d/fuego", - "FUEGOBRANCH":"master", - "FUEGOCOREREPO":"https://bitbucket.org/tbird20d/fuego-core", - "FUEGOCOREBRANCH":"master" + "FUEGO_REPO":"https://bitbucket.org/tbird20d/fuego", + "FUEGO_BRANCH":"master", + "FUEGO_CORE_REPO":"https://bitbucket.org/tbird20d/fuego-core", + "FUEGO_CORE_BRANCH":"master" } } }
Signature · 1 line
2.16.3
PATCH 3/8 Add specs for 'test' and 'next' branches
In reply to Guilherme Campos CamargoTesting the branches 'test' and 'next' are very common use-case for the fuego-release-test. For that reason, it's a good idea to provide specs for them on the specs.json file.
--- engine/tests/Functional.fuego_release_test/spec.json | 12 ++++++++++++ 1 file changed, 12 insertions(+)
engine/tests/Functional.fuego_release_test/spec.json +12 -0
@@ -6,6 +6,18 @@ "FUEGO_BRANCH":"master", "FUEGO_CORE_REPO":"https://bitbucket.org/tbird20d/fuego-core", "FUEGO_CORE_BRANCH":"master" + }, + "test": { + "FUEGO_REPO":"https://bitbucket.org/tbird20d/fuego", + "FUEGO_BRANCH":"test", + "FUEGO_CORE_REPO":"https://bitbucket.org/tbird20d/fuego-core", + "FUEGO_CORE_BRANCH":"test" + }, + "next": { + "FUEGO_REPO":"https://bitbucket.org/tbird20d/fuego", + "FUEGO_BRANCH":"next", + "FUEGO_CORE_REPO":"https://bitbucket.org/tbird20d/fuego-core", + "FUEGO_CORE_BRANCH":"next" } } }
Signature · 1 line
2.16.3
PATCH 4/8 Replace single-quote with double-quotes on long strings
In reply to Guilherme Campos CamargoUse double-quotes to avoid having to scape single-quotes and apostrophes. All long strings, that represent something that's human readable has also been surrounded with double-quotes for consistency.
Short strings that are only used internally on the code (dictionary keys and commands for example, are kept with single-quotes.
--- .../Functional.fuego_release_test/test_run.py | 130 ++++++++++----------- 1 file changed, 65 insertions(+), 65 deletions(-)
engine/tests/Functional.fuego_release_test/test_run.py +65 -65
@@ -19,21 +19,21 @@ import selenium.common.exceptions as selenium_exceptions LOGGER = logging.getLogger('test_run') STREAM_HANDLER = logging.StreamHandler() STREAM_HANDLER.setFormatter( - logging.Formatter('%(name)s:%(levelname)s: %(message)s')) + logging.Formatter("%(name)s:%(levelname)s: %(message)s")) LOGGER.setLevel(logging.DEBUG) LOGGER.addHandler(STREAM_HANDLER) def loop_until_timeout(func, timeout=10, num_tries=5): - LOGGER.debug('Running %s()', func.__name__) + LOGGER.debug("Running %s()", func.__name__) for _ in range(num_tries): - LOGGER.debug(' Try number %s...', _ + 1) + LOGGER.debug(" Try number %s...", _ + 1) if func(): - LOGGER.debug(' Success') + LOGGER.debug(" Success") return True time.sleep(timeout/num_tries) - LOGGER.debug(' Failure') + LOGGER.debug(" Failure") return False
@@ -42,7 +42,7 @@ class SeleniumCommand: def exec(self, selenium_ctx): self.driver = selenium_ctx.driver self.driver.refresh() - LOGGER.debug('Executing Selenium Command \'%s\'', + LOGGER.debug("Executing Selenium Command '%s'", self.__class__.__name__) @staticmethod
@@ -50,28 +50,28 @@ class SeleniumCommand: try: if text in element.text: LOGGER.\ - debug(' Text \'%s\' matches element.text \'%s\'', + debug(" Text '%s' matches element.text '%s'", text, element.text) return True else: LOGGER.\ - debug(' Text \'%s\' does not match element.text \'%s\'', + debug(" Text '%s' does not match element.text '%s'", text, element.text) return False except (selenium_exceptions.ElementNotVisibleException, selenium_exceptions.NoSuchAttributeException,): - LOGGER.error(' Element has no visible Text') + LOGGER.error(" Element has no visible Text") return False @staticmethod def click_element(element): try: element.click() - LOGGER.debug(' Element clicked') + LOGGER.debug(" Element clicked") return True except (selenium_exceptions.ElementClickInterceptedException, selenium_exceptions.ElementNotVisibleException,): - LOGGER.error(' Element is not clickable') + LOGGER.error(" Element is not clickable") return False @staticmethod
@@ -79,10 +79,10 @@ class SeleniumCommand: try: element = context.driver.find_element(locator, pattern) except selenium_exceptions.NoSuchElementException: - LOGGER.error(' Element not found') + LOGGER.error(" Element not found") return None - LOGGER.debug(' Element found') + LOGGER.debug(" Element found") return element
@@ -95,16 +95,16 @@ class Visit(SeleniumCommand): def exec(self, selenium_ctx): super().exec(selenium_ctx) - LOGGER.debug(' Visiting \'%s\'', self.url) + LOGGER.debug(" Visiting '%s'", self.url) self.driver.get(self.url) r = requests.get(self.url) if r.status_code != self.expected_result: - LOGGER.debug(' HTTP Status Code \'%s\' is different ' - 'from the expected \'%s\'', r.status_cod, self.url) + LOGGER.debug(" HTTP Status Code '%s' is different " + "from the expected '%s'", r.status_cod, self.url) return False - LOGGER.debug(' HTTP Status Code is same as expected \'%s\'', + LOGGER.debug(" HTTP Status Code is same as expected '%s'", r.status_code) return True
@@ -147,7 +147,7 @@ class Back(SeleniumCommand): def exec(self, selenium_ctx): super().exec(selenium_ctx) - LOGGER.debug(' Going back') + LOGGER.debug(" Going back") self.driver.back() return True
@@ -170,7 +170,7 @@ class ShExpect(): def exec(self, pexpect_ctx): self.client = pexpect_ctx.client - LOGGER.debug('Executing command \'%s\'', self.cmd) + LOGGER.debug("Executing command '%s'", self.cmd) try: self.client.sendline('{}=$({} 2>&1)'.format( self.OUTPUT_VARIABLE, self.cmd))
@@ -188,22 +188,22 @@ class ShExpect(): out = self.client.match.group(1) if result != self.expected_result: - LOGGER.error('The command \'%s\' returned the code \'%d\', ' - 'but the expected code is \'%d\'' - '\nCommand output: \'%s\'', + LOGGER.error("The command '%s' returned the code '%d', " + "but the expected code is '%d'" + "\nCommand output: '%s'", self.cmd, result, self.expected_result, out) return False if self.expected_output is not None and \ re.search(self.expected_output, out) is None: - LOGGER.error('Wrong output for command \'%s\'. ' - 'Expected \'%s\'\nReceived \'%s\'', + LOGGER.error("Wrong output for command '%s'. " + "Expected '%s'\nReceived '%s'", self.cmd, self.expected_output, out) return False except pexpect.exceptions.TIMEOUT: - LOGGER.error('Timeout for command \'%s\'', self.cmd) + LOGGER.error("Timeout for command '%s'", self.cmd) return False except pexpect.exceptions.EOF: - LOGGER.error('Lost connection with docker. Aborting') + LOGGER.error("Lost connection with docker. Aborting") return False return True
@@ -220,10 +220,10 @@ class FuegoContainer: def __del__(self): if self.container: if self.rm_after_test: - LOGGER.debug('Removing Container') + LOGGER.debug("Removing Container") self.container.remove(force=True) else: - LOGGER.debug('Not Removing the test container') + LOGGER.debug("Not Removing the test container") def install(self): self.docker_client = docker.APIClient()
@@ -254,25 +254,25 @@ class FuegoContainer: inspect_container(container_id)['Mounts'] for mount in mounts: - LOGGER.debug(' Trying to find %s mountpoint in the host', + LOGGER.debug(" Trying to find '%s' mountpoint in the host", mount['source']) for host_mount in host_mounts: if mount['source'].startswith(host_mount['Destination']): mount['source'] = mount['source'].\ replace(host_mount['Destination'], host_mount['Source'], 1) - LOGGER.debug(' Found: %s', mount['source']) + LOGGER.debug(" Found: '%s'", mount['source']) break else: - LOGGER.debug(' Not Found') + LOGGER.debug(" Not Found") mount['source'] = None cmd = './{} {}'.format(self.install_script, self.image_name) - LOGGER.debug('Running \'%s\' to install the docker image. ' - 'This may take a while....', cmd) + LOGGER.debug("Running '%s' to install the docker image. " + "This may take a while....", cmd) status = subprocess.call(cmd, shell=True) - LOGGER.debug('Install output code: %s', status) + LOGGER.debug("Install output code: %s", status) if status != 0: return None
@@ -282,7 +282,7 @@ class FuegoContainer: all=True, filters={'name': self.container_name}) if containers: LOGGER.debug( - 'Erasing the container \'%s\', so a new one can be created', + "Erasing the container '%s', so a new one can be created", self.container_name) containers[0].remove(force=True)
@@ -304,13 +304,13 @@ class FuegoContainer: our_id = this_container_id() if our_id: - LOGGER.debug('Running inside the Docker container %s', our_id) + LOGGER.debug("Running inside the Docker container %s", our_id) map_to_host(mounts, our_id) else: - LOGGER.debug('Not running inside a Docker container') + LOGGER.debug("Not running inside a Docker container") - LOGGER.debug('Creating container with the following mountpoints:') - LOGGER.debug(' %s', mounts) + LOGGER.debug("Creating container with the following mountpoints:") + LOGGER.debug(" %s", mounts) container = docker_client.containers.create( self.image_name,
@@ -322,7 +322,7 @@ class FuegoContainer: for m in mounts], name=self.container_name, command='/bin/bash') - LOGGER.debug('Container \'%s\' created', self.container_name) + LOGGER.debug("Container '%s' created", self.container_name) return container def is_running(self):
@@ -352,7 +352,7 @@ class FuegoContainer: return False if container_addr is None else True if not loop_until_timeout(fetch_ip, timeout=10): - LOGGER.error('Could not fetch the container IP address') + LOGGER.error("Could not fetch the container IP address") return None return container_addr
@@ -375,7 +375,7 @@ class PexpectContainerSession(): def start(self): LOGGER.debug( - 'Starting container \'%s\'', self.container.container_name) + "Starting container '%s'", self.container.container_name) self.client = pexpect.spawnu( '{} {}'.format( self.start_script, self.container.container_name),
@@ -408,7 +408,7 @@ class PexpectContainerSession(): status = resp.status conn.close() LOGGER.debug( - ' HTTP Response code: \'%d\' - Jenkins Version: \'%s\'', + " HTTP Response code: '%d' - Jenkins Version: '%s'", status, version) if status == http.client.OK and version is not None: return True
@@ -420,12 +420,12 @@ class PexpectContainerSession(): container_addr = self.container.get_ip() if container_addr is None: return False - LOGGER.debug('Trying to reach jenkins at container \'%s\' via ' - 'the container\'s IP \'%s\' at port \'%d\'', + LOGGER.debug("Trying to reach jenkins at container '%s' via " + "the container's IP '%s' at port '%d'", self.container.container_name, container_addr, self.container.jenkins_port) if not loop_until_timeout(ping_jenkins, timeout=60): - LOGGER.error('Could not connect to jenkins') + LOGGER.error("Could not connect to jenkins") return False return True
@@ -450,7 +450,7 @@ class SeleniumContainerSession(): self.driver.get(self.root_url) - LOGGER.debug('Started a Selenium Session on %s', self.root_url) + LOGGER.debug("Started a Selenium Session on %s", self.root_url) return True def __del__(self):
@@ -467,7 +467,7 @@ def main(): DEFAULT_JENKINS_PORT = 8080 def execute_tests(timeout): - LOGGER.debug('Starting tests') + LOGGER.debug("Starting tests") ctx_mapper = { ShExpect: pexpect_session,
@@ -483,51 +483,51 @@ def main(): break if tests_ok: - LOGGER.debug('Tests finished.') + LOGGER.debug("Tests finished.") return tests_ok parser = argparse.ArgumentParser() - parser.add_argument('working_dir', help='The working directory', type=str) + parser.add_argument('working_dir', help="The working directory", type=str) parser.add_argument('-s', '--install-script', - help='The script that will be used to install the ' - 'docker image. Defaults to \'{}\'' + help="The script that will be used to install the " + "docker image. Defaults to '{}'" .format(DEFAULT_INSTALL_SCRIPT), default=DEFAULT_INSTALL_SCRIPT, type=str) parser.add_argument('-a', '--start-script', - help='The script used to start the container. ' - 'Defaults to \'{}\'' + help="The script used to start the container. " + "Defaults to '{}'" .format(DEFAULT_START_SCRIPT), default=DEFAULT_START_SCRIPT, type=str) parser.add_argument('-i', '--image-name', default=DEFAULT_IMAGE_NAME, - help='The image name that should be used. ' - 'Defaults to \'{}\'' + help="The image name that should be used. " + "Defaults to '{}'" .format(DEFAULT_IMAGE_NAME), type=str) parser.add_argument('-c', '--container-name', default=DEFAULT_CONTAINER_NAME, - help='The container name that should be used for the ' - 'test. Defaults to \'{}\'' + help="The container name that should be used for the " + "test. Defaults to '{}'" .format(DEFAULT_CONTAINER_NAME), type=str) - parser.add_argument('-t', '--timeout', help='The timeout value for ' - 'commands. Defaults to {}' + parser.add_argument('-t', '--timeout', help="The timeout value for " + "commands. Defaults to {}" .format(DEFAULT_TIMEOUT), default=DEFAULT_TIMEOUT, type=int) parser.add_argument('-j', '--jenkins-port', - help='The port where the jenkins is running on the ' - 'test container. Defaults to {}' + help="The port where the jenkins is running on the " + "test container. Defaults to {}" .format(DEFAULT_JENKINS_PORT), default=DEFAULT_JENKINS_PORT, type=int) parser.add_argument('--no-rm-container', - help='Do not remove the container after tests are ' - 'complete.', + help="Do not remove the container after tests are " + "complete.", dest='rm_test_container', default=True, action='store_false') args = parser.parse_args() - LOGGER.debug('Changing working dir to \'%s\'', args.working_dir) + LOGGER.debug("Changing working dir to '%s'", args.working_dir) os.chdir(args.working_dir) container = FuegoContainer(args.install_script, args.image_name,
Signature · 1 line
2.16.3
PATCH 5/8 Use '+' on long wrapped strings to show contatenation explicitly
In reply to Guilherme Campos CamargoImproves readability by explicitly showing that strings are being concatenated with the '+' operator.
--- .../Functional.fuego_release_test/test_run.py | 31 +++++++++++----------- 1 file changed, 16 insertions(+), 15 deletions(-)
engine/tests/Functional.fuego_release_test/test_run.py +16 -15
@@ -100,7 +100,7 @@ class Visit(SeleniumCommand): r = requests.get(self.url) if r.status_code != self.expected_result: - LOGGER.debug(" HTTP Status Code '%s' is different " + LOGGER.debug(" HTTP Status Code '%s' is different " + "from the expected '%s'", r.status_cod, self.url) return False
@@ -188,14 +188,14 @@ class ShExpect(): out = self.client.match.group(1) if result != self.expected_result: - LOGGER.error("The command '%s' returned the code '%d', " - "but the expected code is '%d'" + LOGGER.error("The command '%s' returned the code '%d', " + + "but the expected code is '%d'" + "\nCommand output: '%s'", self.cmd, result, self.expected_result, out) return False if self.expected_output is not None and \ re.search(self.expected_output, out) is None: - LOGGER.error("Wrong output for command '%s'. " + LOGGER.error("Wrong output for command '%s'. " + "Expected '%s'\nReceived '%s'", self.cmd, self.expected_output, out) return False
@@ -268,7 +268,7 @@ class FuegoContainer: mount['source'] = None cmd = './{} {}'.format(self.install_script, self.image_name) - LOGGER.debug("Running '%s' to install the docker image. " + LOGGER.debug("Running '%s' to install the docker image. " + "This may take a while....", cmd) status = subprocess.call(cmd, shell=True)
@@ -420,7 +420,7 @@ class PexpectContainerSession(): container_addr = self.container.get_ip() if container_addr is None: return False - LOGGER.debug("Trying to reach jenkins at container '%s' via " + LOGGER.debug("Trying to reach jenkins at container '%s' via " + "the container's IP '%s' at port '%d'", self.container.container_name, container_addr, self.container.jenkins_port)
@@ -490,38 +490,38 @@ def main(): parser = argparse.ArgumentParser() parser.add_argument('working_dir', help="The working directory", type=str) parser.add_argument('-s', '--install-script', - help="The script that will be used to install the " + help="The script that will be used to install the " + "docker image. Defaults to '{}'" .format(DEFAULT_INSTALL_SCRIPT), default=DEFAULT_INSTALL_SCRIPT, type=str) parser.add_argument('-a', '--start-script', - help="The script used to start the container. " + help="The script used to start the container. " + "Defaults to '{}'" .format(DEFAULT_START_SCRIPT), default=DEFAULT_START_SCRIPT, type=str) parser.add_argument('-i', '--image-name', default=DEFAULT_IMAGE_NAME, - help="The image name that should be used. " + help="The image name that should be used. " + "Defaults to '{}'" .format(DEFAULT_IMAGE_NAME), type=str) parser.add_argument('-c', '--container-name', default=DEFAULT_CONTAINER_NAME, - help="The container name that should be used for the " - "test. Defaults to '{}'" + help="The container name that should be used for " + + "the test. Defaults to '{}'" .format(DEFAULT_CONTAINER_NAME), type=str) - parser.add_argument('-t', '--timeout', help="The timeout value for " + parser.add_argument('-t', '--timeout', help="The timeout value for " + "commands. Defaults to {}" .format(DEFAULT_TIMEOUT), default=DEFAULT_TIMEOUT, type=int) parser.add_argument('-j', '--jenkins-port', - help="The port where the jenkins is running on the " + help="The port where the jenkins is running on the " + "test container. Defaults to {}" .format(DEFAULT_JENKINS_PORT), default=DEFAULT_JENKINS_PORT, type=int) parser.add_argument('--no-rm-container', - help="Do not remove the container after tests are " + help="Do not remove the container after tests are " + "complete.", dest='rm_test_container', default=True, action='store_false')
@@ -576,7 +576,8 @@ def main(): # Start a Test through Jenkins UI (Xpath) Click(By.XPATH, - '//img[@title="Schedule a build for docker.default.Functional.hello_world"]'), + '//img[@title="Schedule a build for ' + + 'docker.default.Functional.hello_world"]'), CheckText(By.ID, 'executors', text='docker.default.Functional.hello_world'), ]
Signature · 1 line
2.16.3
PATCH 6/8 Avoid reordering conditional logic to improve readability
In reply to Guilherme Campos CamargoReplace Python's ternary conditional operation with the traditional multi-line if/else to improve readability.
--- engine/tests/Functional.fuego_release_test/test_run.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
engine/tests/Functional.fuego_release_test/test_run.py +4 -1
@@ -349,7 +349,10 @@ class FuegoContainer: except KeyError: return False - return False if container_addr is None else True + if container_addr is None: + return False + else: + return True if not loop_until_timeout(fetch_ip, timeout=10): LOGGER.error("Could not fetch the container IP address")
Signature · 1 line
2.16.3
PATCH 7/8 Keep the output of the test in TAP format
In reply to Guilherme Campos CamargoWe're trying to stay with TAP format where possible. With that format, the test output is written as:
``` [not] ok 1 fuego release test ```
--- engine/tests/Functional.fuego_release_test/fuego_test.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
engine/tests/Functional.fuego_release_test/fuego_test.sh +3 -3
@@ -24,12 +24,12 @@ function test_build { function test_run { sudo -n ${TEST_HOME}/test_run.py "${fuego_release_dir}/fuego" if [ "${?}" = 0 ]; then - report "echo fuego-test: ok" + report "echo ok 1 fuego release test" else - report "echo fuego-test: fail" + report "echo not ok 1 fuego release test" fi } function test_processing { - log_compare "$TESTDIR" "1" "ok$" "p" + log_compare "$TESTDIR" "1" "^ok" "p" }
Signature · 1 line
2.16.3
PATCH 8/8 Use atexit to remove the docker container after the test
In reply to Guilherme Campos CamargoBy using the destructor __del__ in the FuegoContainer class, there were occasions when self.container.delete failed to execute with an exception raised from the docker client, probably due to required resources having been release before the container deletion.
By using atexit, it's guaranteed that the registered method (cleanup()) will be called when main() exits, while all the resources are still available, not causing such problem.
--- engine/tests/Functional.fuego_release_test/test_run.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
engine/tests/Functional.fuego_release_test/test_run.py +7 -1
@@ -1,5 +1,6 @@ #!/usr/bin/env python3 import argparse +import atexit import http import http.client import logging
@@ -217,7 +218,7 @@ class FuegoContainer: self.jenkins_port = jenkins_port self.rm_after_test = rm_after_test - def __del__(self): + def delete(self): if self.container: if self.rm_after_test: LOGGER.debug("Removing Container")
@@ -469,6 +470,11 @@ def main(): DEFAULT_START_SCRIPT = 'fuego-host-scripts/docker-start-container.sh' DEFAULT_JENKINS_PORT = 8080 + @atexit.register + def cleanup(): + if container: + container.delete() + def execute_tests(timeout): LOGGER.debug("Starting tests")
Signature · 1 line
2.16.3
Quoted 9 lines
-----Original Message-----
From: Guilherme Campos Camargo
Hello, everyone.This series of patches implements Tim's suggestions on top of the original patches that have been sent last week and integrated into fuego-core/master.
Thanks. I did a very brief review, and things looked OK.
All patches applied and pushed. I did have one question, which I'll ask on a related patch.
-- Tim
Quoted 31 lines
Guilherme Campos Camargo (8):
Rename Functional.fuegotest to Functional.fuego_release_test Add underscores to variables in spec.json
Add specs for 'test' and 'next' branches
Replace single-quote with double-quotes on long strings Use '+' on long wrapped strings to show contatenation explicitly Avoid reordering conditional logic to improve readability Keep the output of the test in TAP format
Use atexit to remove the docker container after the test.../Functional.fuego_release_test/fuego_test.sh | 35 +++++ .../tests/Functional.fuego_release_test/spec.json | 23 ++++ .../test_run.py | 146 +++++++++++---------- engine/tests/Functional.fuegotest/fuego_test.sh | 36 ----- engine/tests/Functional.fuegotest/spec.json | 11 -- 5 files changed, 136 insertions(+), 115 deletions(-) create mode 100755 engine/tests/Functional.fuego_release_test/fuego_test.sh create mode 100644 engine/tests/Functional.fuego_release_test/spec.json rename engine/tests/{Functional.fuegotest => Functional.fuego_release_test}/test_run.py (78%) delete mode 100755 engine/tests/Functional.fuegotest/fuego_test.sh delete mode 100644 engine/tests/Functional.fuegotest/spec.json--
2.16.3_______________________________________________
Fuego mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/fuego