Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:crameleon:misc
scullery
_service:obs_scm:scullery-0.2.obscpio
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File _service:obs_scm:scullery-0.2.obscpio of Package scullery
07070100000000000081A4000000000000000000000001646D49F400000023000000000000000000000000000000000000001800000000scullery-0.2/.gitignore.vagrant/ __pycache__/ .scullery_* 07070100000001000081A4000000000000000000000001646D49F400003603000000000000000000000000000000000000001500000000scullery-0.2/LICENSE EUROPEAN UNION PUBLIC LICENCE v. 1.2 EUPL © the European Union 2007, 2016 This European Union Public Licence (the ‘EUPL’) applies to the Work (as defined below) which is provided under the terms of this Licence. Any use of the Work, other than as authorised under this Licence is prohibited (to the extent such use is covered by a right of the copyright holder of the Work). The Work is provided under the terms of this Licence when the Licensor (as defined below) has placed the following notice immediately following the copyright notice for the Work: Licensed under the EUPL or has expressed by any other means his willingness to license under the EUPL. 1. Definitions In this Licence, the following terms have the following meaning: - ‘The Licence’: this Licence. - ‘The Original Work’: the work or software distributed or communicated by the Licensor under this Licence, available as Source Code and also as Executable Code as the case may be. - ‘Derivative Works’: the works or software that could be created by the Licensee, based upon the Original Work or modifications thereof. This Licence does not define the extent of modification or dependence on the Original Work required in order to classify a work as a Derivative Work; this extent is determined by copyright law applicable in the country mentioned in Article 15. - ‘The Work’: the Original Work or its Derivative Works. - ‘The Source Code’: the human-readable form of the Work which is the most convenient for people to study and modify. - ‘The Executable Code’: any code which has generally been compiled and which is meant to be interpreted by a computer as a program. - ‘The Licensor’: the natural or legal person that distributes or communicates the Work under the Licence. - ‘Contributor(s)’: any natural or legal person who modifies the Work under the Licence, or otherwise contributes to the creation of a Derivative Work. - ‘The Licensee’ or ‘You’: any natural or legal person who makes any usage of the Work under the terms of the Licence. - ‘Distribution’ or ‘Communication’: any act of selling, giving, lending, renting, distributing, communicating, transmitting, or otherwise making available, online or offline, copies of the Work or providing access to its essential functionalities at the disposal of any other natural or legal person. 2. Scope of the rights granted by the Licence The Licensor hereby grants You a worldwide, royalty-free, non-exclusive, sublicensable licence to do the following, for the duration of copyright vested in the Original Work: - use the Work in any circumstance and for all usage, - reproduce the Work, - modify the Work, and make Derivative Works based upon the Work, - communicate to the public, including the right to make available or display the Work or copies thereof to the public and perform publicly, as the case may be, the Work, - distribute the Work or copies thereof, - lend and rent the Work or copies thereof, - sublicense rights in the Work or copies thereof. Those rights can be exercised on any media, supports and formats, whether now known or later invented, as far as the applicable law permits so. In the countries where moral rights apply, the Licensor waives his right to exercise his moral right to the extent allowed by law in order to make effective the licence of the economic rights here above listed. The Licensor grants to the Licensee royalty-free, non-exclusive usage rights to any patents held by the Licensor, to the extent necessary to make use of the rights granted on the Work under this Licence. 3. Communication of the Source Code The Licensor may provide the Work either in its Source Code form, or as Executable Code. If the Work is provided as Executable Code, the Licensor provides in addition a machine-readable copy of the Source Code of the Work along with each copy of the Work that the Licensor distributes or indicates, in a notice following the copyright notice attached to the Work, a repository where the Source Code is easily and freely accessible for as long as the Licensor continues to distribute or communicate the Work. 4. Limitations on copyright Nothing in this Licence is intended to deprive the Licensee of the benefits from any exception or limitation to the exclusive rights of the rights owners in the Work, of the exhaustion of those rights or of other applicable limitations thereto. 5. Obligations of the Licensee The grant of the rights mentioned above is subject to some restrictions and obligations imposed on the Licensee. Those obligations are the following: Attribution right: The Licensee shall keep intact all copyright, patent or trademarks notices and all notices that refer to the Licence and to the disclaimer of warranties. The Licensee must include a copy of such notices and a copy of the Licence with every copy of the Work he/she distributes or communicates. The Licensee must cause any Derivative Work to carry prominent notices stating that the Work has been modified and the date of modification. Copyleft clause: If the Licensee distributes or communicates copies of the Original Works or Derivative Works, this Distribution or Communication will be done under the terms of this Licence or of a later version of this Licence unless the Original Work is expressly distributed only under this version of the Licence — for example by communicating ‘EUPL v. 1.2 only’. The Licensee (becoming Licensor) cannot offer or impose any additional terms or conditions on the Work or Derivative Work that alter or restrict the terms of the Licence. Compatibility clause: If the Licensee Distributes or Communicates Derivative Works or copies thereof based upon both the Work and another work licensed under a Compatible Licence, this Distribution or Communication can be done under the terms of this Compatible Licence. For the sake of this clause, ‘Compatible Licence’ refers to the licences listed in the appendix attached to this Licence. Should the Licensee's obligations under the Compatible Licence conflict with his/her obligations under this Licence, the obligations of the Compatible Licence shall prevail. Provision of Source Code: When distributing or communicating copies of the Work, the Licensee will provide a machine-readable copy of the Source Code or indicate a repository where this Source will be easily and freely available for as long as the Licensee continues to distribute or communicate the Work. Legal Protection: This Licence does not grant permission to use the trade names, trademarks, service marks, or names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the copyright notice. 6. Chain of Authorship The original Licensor warrants that the copyright in the Original Work granted hereunder is owned by him/her or licensed to him/her and that he/she has the power and authority to grant the Licence. Each Contributor warrants that the copyright in the modifications he/she brings to the Work are owned by him/her or licensed to him/her and that he/she has the power and authority to grant the Licence. Each time You accept the Licence, the original Licensor and subsequent Contributors grant You a licence to their contributions to the Work, under the terms of this Licence. 7. Disclaimer of Warranty The Work is a work in progress, which is continuously improved by numerous Contributors. It is not a finished work and may therefore contain defects or ‘bugs’ inherent to this type of development. For the above reason, the Work is provided under the Licence on an ‘as is’ basis and without warranties of any kind concerning the Work, including without limitation merchantability, fitness for a particular purpose, absence of defects or errors, accuracy, non-infringement of intellectual property rights other than copyright as stated in Article 6 of this Licence. This disclaimer of warranty is an essential part of the Licence and a condition for the grant of any rights to the Work. 8. Disclaimer of Liability Except in the cases of wilful misconduct or damages directly caused to natural persons, the Licensor will in no event be liable for any direct or indirect, material or moral, damages of any kind, arising out of the Licence or of the use of the Work, including without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, loss of data or any commercial damage, even if the Licensor has been advised of the possibility of such damage. However, the Licensor will be liable under statutory product liability laws as far such laws apply to the Work. 9. Additional agreements While distributing the Work, You may choose to conclude an additional agreement, defining obligations or services consistent with this Licence. However, if accepting obligations, You may act only on your own behalf and on your sole responsibility, not on behalf of the original Licensor or any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against such Contributor by the fact You have accepted any warranty or additional liability. 10. Acceptance of the Licence The provisions of this Licence can be accepted by clicking on an icon ‘I agree’ placed under the bottom of a window displaying the text of this Licence or by affirming consent in any other similar way, in accordance with the rules of applicable law. Clicking on that icon indicates your clear and irrevocable acceptance of this Licence and all of its terms and conditions. Similarly, you irrevocably accept this Licence and all of its terms and conditions by exercising any rights granted to You by Article 2 of this Licence, such as the use of the Work, the creation by You of a Derivative Work or the Distribution or Communication by You of the Work or copies thereof. 11. Information to the public In case of any Distribution or Communication of the Work by means of electronic communication by You (for example, by offering to download the Work from a remote location) the distribution channel or media (for example, a website) must at least provide to the public the information requested by the applicable law regarding the Licensor, the Licence and the way it may be accessible, concluded, stored and reproduced by the Licensee. 12. Termination of the Licence The Licence and the rights granted hereunder will terminate automatically upon any breach by the Licensee of the terms of the Licence. Such a termination will not terminate the licences of any person who has received the Work from the Licensee under the Licence, provided such persons remain in full compliance with the Licence. 13. Miscellaneous Without prejudice of Article 9 above, the Licence represents the complete agreement between the Parties as to the Work. If any provision of the Licence is invalid or unenforceable under applicable law, this will not affect the validity or enforceability of the Licence as a whole. Such provision will be construed or reformed so as necessary to make it valid and enforceable. The European Commission may publish other linguistic versions or new versions of this Licence or updated versions of the Appendix, so far this is required and reasonable, without reducing the scope of the rights granted by the Licence. New versions of the Licence will be published with a unique version number. All linguistic versions of this Licence, approved by the European Commission, have identical value. Parties can take advantage of the linguistic version of their choice. 14. Jurisdiction Without prejudice to specific agreement between parties, - any litigation resulting from the interpretation of this License, arising between the European Union institutions, bodies, offices or agencies, as a Licensor, and any Licensee, will be subject to the jurisdiction of the Court of Justice of the European Union, as laid down in article 272 of the Treaty on the Functioning of the European Union, - any litigation arising between other parties and resulting from the interpretation of this License, will be subject to the exclusive jurisdiction of the competent court where the Licensor resides or conducts its primary business. 15. Applicable Law Without prejudice to specific agreement between parties, - this Licence shall be governed by the law of the European Union Member State where the Licensor has his seat, resides or has his registered office, - this licence shall be governed by Belgian law if the Licensor has no seat, residence or registered office inside a European Union Member State. Appendix ‘Compatible Licences’ according to Article 5 EUPL are: - GNU General Public License (GPL) v. 2, v. 3 - GNU Affero General Public License (AGPL) v. 3 - Open Software License (OSL) v. 2.1, v. 3.0 - Eclipse Public License (EPL) v. 1.0 - CeCILL v. 2.0, v. 2.1 - Mozilla Public Licence (MPL) v. 2 - GNU Lesser General Public Licence (LGPL) v. 2.1, v. 3 - Creative Commons Attribution-ShareAlike v. 3.0 Unported (CC BY-SA 3.0) for works other than software - European Union Public Licence (EUPL) v. 1.1, v. 1.2 - Québec Free and Open-Source Licence — Reciprocity (LiLiQ-R) or Strong Reciprocity (LiLiQ-R+). The European Commission may update this Appendix to later versions of the above licences without producing a new version of the EUPL, as long as they provide the rights granted in Article 2 of this Licence and protect the covered Source Code from exclusive appropriation. All other changes or additions to this Appendix require the production of a new EUPL version. 07070100000002000081A4000000000000000000000001646D49F400000D11000000000000000000000000000000000000001700000000scullery-0.2/README.md# Scullery This is intended to be a replacement for [KitchenCI](https://test-kitchen.chef.io/) and [kitchen-salt](https://github.com/saltstack/kitchen-salt), focussing on testing SaltStack states using Vagrant and Pytest/Testinfra. ## Installation So far, a packaged installation is possible on openSUSE Tumbleweed: ``` $ zypper ar -f https://download.opensuse.org/repositories/home:/crameleon:/Scullery/openSUSE_Tumbleweed/home:crameleon:Scullery.repo $ zypper in scullery ``` This will pull in `vagrant`, `vagrant-libvirt`, `python3-vagrant`, `python3-pytest` and `python3-pytest-testinfra` as dependencies. Installation on Leap 15.4 is possible, however will currently cause dependency issues with the needed `python-vagrant` library. It is possible to run `scullery.py` from a Git checkout of this repository if the dependencies are resolved manually. Currently the script behaves purely as a console application and imports as a Python module are not supported. ## Basic usage ``` scullery -h usage: scullery [-h] [--debug] [--config CONFIG] [--env] --suite SUITE [--stop | --test | --status | --refresh] [--force-stop] options: -h, --help show this help message and exit --debug Print extremely verbose output --config CONFIG Specify the configuration file to use --env Write environment file for direct use of Vagrant --suite SUITE Specify the suite to run --stop Stop running machines --test Start machines and run tests --status Get Vagrant deployment status --refresh Re-sync files and re-run bootstrap scripts --force-stop Invoke Vagrant destruction without having detected any running VM's ``` ## Command line examples * To run a complete test suite: `$ scullery --suite <name of suite> --test` * To create Vagrant VM's without invoking the tests: `$ scullery --suite <name of suite>` * To refresh the VM's Salt files: `$ scullery --suite <name of suite> --refresh` * To stop the VM's and tidy up: `$ scullery --suite <name of suite> --stop` ## Interacting with Vagrant It is possible to directly interact with the Vagrant environment templated by Scullery. To do so, generate an environment file by adding `--env` to any command line call - for example: `$ scullery --suite <name of suite> --env` This will write a `.scullery_env` file to the current working directory. Export the environment variables in the file using your Shell, afterwards use `vagrant` like you normally would. Example for `bash`/`sh`: ``` $ set -a; . .scullery_env; set +a $ vagrant ssh # or any other Vagrant command ``` Do not forget to unset the exported variables before you call Scullery with a different `--suite`! ## Hacking To test Scullery itself, call Pytest with your favourite arguments from the repository root: ``` $ pytest -v -rx -x tests/*.py ``` Make sure to not have _any_ other Scullery based Vagrant VM's running in the same Libvirt session and no `SCULLERY_*` or `VAGRANT_*` variables exported in your shell. The complete test suite takes about 30 minutes to execute on an Intel i7-6820HQ CPU with SSHD storage. If you want to test only certain functionality, simply add `-k <name of test function>`. ## License This project is licensed under the European Union Public License found in the file `LICENSE`. 07070100000003000081A4000000000000000000000001646D49F4000001F6000000000000000000000000000000000000001500000000scullery-0.2/TODO.md# To-Do's - Introduce `--apply` argument to execute `state.apply` on VM's without chaining to test executions - Do not restart the network stack on `--refresh` (the `systemctl restart network` call is needed on the first boot to get Avahi DNS resolution to work - there is currently no logic to skip the command on subsequent executions of the bootstrap script) - Add example configurations - Use `pyproject.toml` style packaging to allow for installation as a Python module - Resolve Pytest warnings 07070100000004000081A4000000000000000000000001646D49F4000008AA000000000000000000000000000000000000002200000000scullery-0.2/Vagrantfile-Template# -*- mode: ruby -*- # vi: set ft=ruby : if ! ( ENV['SCULLERY_BOX_NAME'] && ENV['SCULLERY_BOX_IMAGE'] ) || ! ( ENV['SCULLERY_MASTERS'] || ENV['SCULLERY_MINIONS'] ) print('Missing parameters') exit 1 end salt_bootstrap = ENV['SCULLERY_BOOTSTRAP'] salt_file_roots = 'file_roots:\n base:\n - /srv/salt\n - /srv/formulas\n' Vagrant.configure("2") do |config| config.vm.provider "libvirt" config.vm.box = ENV['SCULLERY_BOX_NAME'] config.vm.box_url = ENV['SCULLERY_BOX_IMAGE'] config.vm.provision "shell", inline: <<-SHELL systemctl restart network SHELL if ENV['SCULLERY_MASTERS'] ENV['SCULLERY_MASTERS'].split(',').each do |vmname| config.vm.define "#{vmname}", primary: true do |master_config| master_config.vm.hostname = "#{vmname}" master_config.vm.provider :libvirt do |libvirt| libvirt.memory = 768 end master_config.vm.provision "shell", env: {'SALT_FILE_ROOTS': salt_file_roots}, inline: <<-SHELL printf 'auto_accept: True\n' > /etc/salt/master.d/notsecure.conf printf "$SALT_FILE_ROOTS" > /etc/salt/master.d/roots.conf systemctl enable --now salt-master SHELL if salt_bootstrap master_config.vm.provision "shell", path: salt_bootstrap end end end end if ENV['SCULLERY_MINIONS'] ENV['SCULLERY_MINIONS'].split(',').each do |vmname| config.vm.define "#{vmname}" do |minion_config| minion_config.vm.hostname = "#{vmname}" if ENV['SCULLERY_MASTERS'] minion_config.vm.synced_folder '.', '/vagrant', disabled: true minion_config.vm.provision "shell", inline: <<-SHELL sed -i 's/^#master:.*/master: scullery-master0/' /etc/salt/minion systemctl enable --now salt-minion SHELL else minion_config.vm.provision "shell", env: {'SALT_FILE_ROOTS': salt_file_roots}, inline: <<-SHELL printf "$SALT_FILE_ROOTS" > /etc/salt/minion.d/roots.conf SHELL if salt_bootstrap minion_config.vm.provision "shell", path: salt_bootstrap end end end end end end 07070100000005000081ED000000000000000000000001646D49F400002B60000000000000000000000000000000000000001900000000scullery-0.2/scullery.py#!/usr/bin/python3 """ Copyright 2023, Georg Pfuetzenreuter Licensed under the EUPL, Version 1.2 or - as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence"). You may not use this work except in compliance with the Licence. An English copy of the Licence is shipped in a file called LICENSE along with this applications source code. You may obtain copies of the Licence in any of the official languages at https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12. --- Scullery - a SaltStack testing tool. """ from argparse import ArgumentParser from configparser import ConfigParser import logging import os import sys from pytest import ExitCode argparser = ArgumentParser() config = ConfigParser() env = os.environ.copy() arggroup = argparser.add_mutually_exclusive_group() argparser.add_argument('--debug', help='Print extremely verbose output', action='store_const', dest='loglevel', const=logging.DEBUG, default=logging.INFO) argparser.add_argument('--config', help='Specify the configuration file to use', default='{}/scullery.ini'.format(os.getcwd())) argparser.add_argument('--env', help='Write environment file for direct use of Vagrant', action='store_true') argparser.add_argument('--suite', help='Specify the suite to run', required=True) arggroup.add_argument('--stop', help='Stop running machines', action='store_true') arggroup.add_argument('--test', help='Start machines and run tests', action='store_true') arggroup.add_argument('--status', help='Get Vagrant deployment status', action='store_true') arggroup.add_argument('--refresh', help='Re-sync files and re-run bootstrap scripts', action='store_true') argparser.add_argument('--force-stop', help='Invoke Vagrant destruction without having detected any running VM\'s', action='store_true') args = argparser.parse_args() configfile = args.config vmprefix = 'scullery' cwd = os.getcwd() sshfile='{}/.scullery_ssh'.format(cwd) envfile='{}/.scullery_env'.format(cwd) vagfile='Vagrantfile-Template' # replaced in scullery.spec is_packaged = False if is_packaged: vagfile='/usr/share/scullery/{}'.format(vagfile) else: try: me = __file__ except NameError: me = sys.argv[0] vagfile='{}/{}'.format(os.path.abspath(os.path.dirname(me)), vagfile) def _abort(msg): log.error(msg) sys.exit(1) def _config(): configmap = {'boxes': {}, 'suites': {}, 'tests': {}} if not 'box' in config.sections(): _abort('No "box" section found in the configuration file') multis = {'boxes': {'prefix': 'box.', 'singular': 'box'}, 'suites': {'prefix': 'suite.', 'singular': 'suite'}, 'tests': {'prefix': 'test.', 'singular': 'test'}} for multi, multiconf in multis.items(): lowconf = [section for section in config.sections() if section.startswith(multiconf['prefix'])] for section in lowconf: collection = section.replace(multiconf['prefix'], '') configmap[multi][collection] = {} for option in config.options(section): if option in ['masters', 'minions']: value = config.getint(section, option) else: value = config.get(section, option) configmap[multi][collection][option] = value onemulti = multiconf['singular'] if onemulti in config.sections(): for option in config.options(onemulti): for collection in configmap[multi]: if not option in configmap[multi][collection]: configmap[multi][collection][option] = config.get(onemulti, option) if multi in ['boxes', 'suites']: if not len(lowconf): _abort('No {} configured'.format(multi)) log.debug('Config map: {}'.format(str(configmap))) return configmap def _vagrant(quiet=False): return vagrant.Vagrant(quiet_stdout=False, quiet_stderr=quiet) def genvms(flavor, amount): vms = [] for i in range(amount): vms.append('{}-{}{}'.format(vmprefix, flavor, i)) return vms def _setenv(envmap, dump=False): if dump: log.debug('Writing environment variable file') fh = open(envfile, 'w') for variable, value in envmap.items(): if value is not None: if isinstance(value, list): value = ','.join(value) env[variable] = value if dump: fh.write(f'{variable}={value}\n') elif variable in env: del env[variable] if dump: fh.close() def vagrant_env(box_name, box_image, minions=None, masters=None, vagrantfile=None, bootstrap=None): envmap = {'VAGRANT_VAGRANTFILE': vagrantfile, 'SCULLERY_BOX_NAME': box_name, 'SCULLERY_BOX_IMAGE': box_image, 'SCULLERY_MASTERS': masters, 'SCULLERY_MINIONS': minions, 'SCULLERY_BOOTSTRAP': bootstrap} log.debug('Environment variable map: {}'.format(str(envmap))) _setenv(envmap, args.env) v.env = env def vagrant_isup(suite): ok = 0 nok = 0 statuses = v.status() total = len(statuses) for status in statuses: if status.state == 'running': ok += 1 else: nok +=1 if ok == total: return True, None elif nok == total: return False, True else: return False, False def vagrant_sshconfig(outfile): try: ssh_config = v.ssh_config() except Exception as myerror: log.exception(myerror) log.error('Unable to fetch SSH configuration') with open(outfile, 'w') as fh: fh.write(ssh_config) def _saltcmd(target): if target == 'local': saltcmd = 'salt-call --local' else: saltcmd = 'salt -t10 {}'.format(target) return saltcmd def runping(target): saltcmd = _saltcmd(target) sshout = v.ssh(command='sudo {} test.ping'.format(saltcmd)) log.info('\n{}\n'.format(str(sshout))) return sshout def runapply(state, target): saltcmd = _saltcmd(target) sshout = v.ssh(command='sudo {} state.apply {}'.format(saltcmd, state)) log.info('\n{}\n'.format(str(sshout))) def runtests(payload, hosts): vagrant_sshconfig(sshfile) testresult = pytest.main(['--verbose', '--hosts={}'.format(','.join(hosts)), '--ssh-config={}'.format(sshfile), payload]) log.debug('Test result is {}'.format(str(testresult.value))) if testresult == ExitCode.OK: log.debug('Test succeeded') else: log.warning('Tests failed') return False return True def _cleanup(): for file in [envfile, sshfile]: if os.path.isfile(file): log.debug('Removing {}'.format(file)) os.remove(file) def main_interactive(): configmap = _config() boxes = configmap['boxes'] suites = configmap['suites'] tests = configmap['tests'] suite = args.suite if suite not in suites: _abort('No suite named {}'.format(suite)) suiteconf = configmap['suites'][suite] box = suiteconf.get('box', None) if box is None: _abort('Specified suite does not reference a box') boxconf = configmap['boxes'].get(box, None) if boxconf is None: _abort('Suite references an undefined box') box_name = boxconf.get('name', None) box_image = boxconf.get('image', None) box_file = boxconf.get('file', vagfile) if None in [box_name, box_image, box_file]: _abort('Box configuration is incomplete') box_bootstrap = boxconf.get('bootstrap', None) minions = None masters = None if suiteconf.get('minions', 0) > 0: minions = genvms('minion', suiteconf['minions']) if suiteconf.get('masters', 0) > 0: masters = genvms('master', suiteconf['masters']) vagrant_env(box_name, box_image, minions, masters, box_file, box_bootstrap) if args.status: log.info('Status report: {}'.format(v.status())) return True status = vagrant_isup(suite) if status[0] is True and status[1] is None or args.force_stop: if True in [args.stop, args.force_stop]: log.info('Destroying machines ...') v.destroy() if vagrant_isup(suite)[0] is False: log.debug('OK') else: _abort('Destruction failed') elif not args.refresh and not args.test: log.info('Deployment is already running') elif args.refresh: log.info('Deployment is running, initiating refresh ...') _cleanup() v.provision() vagrant_sshconfig(sshfile) elif status[0] is False: if status[1] is True: log.debug('Deployment is not running') elif status[1] is False: log.warning('Deployment is in an inconsistent state, destroying ...') try: v.destroy() except Exception as myerror: log.exception(myerror) _abort('Unhandled error') if args.stop is False and args.force_stop is False: log.info('Launching {} ...'.format(suite)) v.up() if vagrant_isup(suite)[0] is True: log.debug('OK') else: _abort('Start failed') if args.stop: _cleanup() if args.test: test = suiteconf.get('test', None) if test is None: _abort('Tests requested but not declared in suite configuration') if not test in tests: _abort('Specified test is not defined') testconf = tests[test] if not 'test' in testconf: _abort('Incomplete test configuration') if 'apply' in testconf: log.debug('state.apply requested') if masters is not None: target = 'scullery-*' count = 0 while not runping(target): if count == 5: _abort('Unable to reach minions') count += 1 else: target = 'local' runapply(testconf['apply'], target) else: log.warning('No state.apply requested') log.info('Initiating tests ...') runtests(testconf['test'], minions) logging.basicConfig(format='%(asctime)s %(levelname)s - %(funcName)s: %(message)s', datefmt='%H:%M:%S') log = logging.getLogger('scullery') if __name__ == '__main__': log.setLevel(args.loglevel) log.debug(args) if args.loglevel == logging.WARNING: quiet_stderr = True else: quiet_stderr = False log.debug('Vagrant stderr: {}'.format(str(quiet_stderr))) try: import vagrant except ImportError as myerror: _abort('Could not load python-vagrant') if args.test: try: import pytest except ImportError as myerror: _abort('Could not load pytest') if os.path.isfile(configfile): config.read(configfile) else: _abort('Unable to locate configuration file at {}'.format(configfile)) if __name__ == '__main__': v = _vagrant(quiet_stderr) main_interactive() else: v = _vagrant() 07070100000006000041ED000000000000000000000005646D49F400000000000000000000000000000000000000000000001300000000scullery-0.2/tests07070100000007000081A4000000000000000000000001646D49F400001EAD000000000000000000000000000000000000002200000000scullery-0.2/tests/01_test_cli.py""" Copyright 2023, Georg Pfuetzenreuter Licensed under the EUPL, Version 1.2 or - as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence"). You may not use this work except in compliance with the Licence. An English copy of the Licence is shipped in a file called LICENSE along with this applications source code. You may obtain copies of the Licence in any of the official languages at https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12. --- Testing functions for Scullery - a SaltStack testing tool. """ import pytest import os import dotenv def test_no_arguments(script_runner, script): result = script_runner.run(script) assert result.success is False assert 'the following arguments are required: --suite' in result.stderr def test_no_config(script_runner, script): result = script_runner.run(script, '--suite', 'foo', print_result=True) assert result.success is False assert 'Unable to locate configuration file' in result.stderr @pytest.mark.parametrize('section,message', [ ('box', 'No "box" section found in the configuration file'), ('suites', 'No suites configured'), ('boxes', 'No boxes configured'), ('suite_box', 'Specified suite does not reference a box'), ('box_name', 'Box configuration is incomplete'), ('box_image', 'Box configuration is incomplete'), ]) def test_config_incomplete(script_runner, script, testbase, section, message): configfile = '{}/configs/missing_{}.ini'.format(testbase, section) result = script_runner.run(script, '--config', configfile, '--suite', 'one_minion') assert result.success is False assert message in result.stderr @pytest.mark.parametrize('section,message', [ ('suite_box', 'Suite references an undefined box') ]) def test_config_undefined(script_runner, script, testbase, section, message): configfile = '{}/configs/undefined_{}.ini'.format(testbase, section) result = script_runner.run(script, '--config', configfile, '--suite', 'one_minion') assert result.success is False assert message in result.stderr @pytest.mark.parametrize('config', ['complete'], indirect=True) @pytest.mark.parametrize('suite,report', [ ('one_minion', "[Status(name='scullery-minion0', state='not_created', provider='libvirt')]"), ('two_minions', "[Status(name='scullery-minion0', state='not_created', provider='libvirt'), Status(name='scullery-minion1', state='not_created', provider='libvirt')]"), ('one_master', "[Status(name='scullery-master0', state='not_created', provider='libvirt')]"), ('one_minion_one_master', "[Status(name='scullery-master0', state='not_created', provider='libvirt'), Status(name='scullery-minion0', state='not_created', provider='libvirt')]"), ('two_minions_one_master', "[Status(name='scullery-master0', state='not_created', provider='libvirt'), Status(name='scullery-minion0', state='not_created', provider='libvirt'), Status(name='scullery-minion1', state='not_created', provider='libvirt')]") ]) def test_status_report_not_running(script_runner, script, config, suite, report): result = script_runner.run(script, '--config', config, '--suite', suite, '--status', '--debug', '--env') assert result.success assert result.stderr.endswith("INFO - main_interactive: Status report: {}\n".format(report)) @pytest.mark.parametrize('config', ['complete'], indirect=True) @pytest.mark.parametrize('suite', [ 'one_minion', 'two_minions', 'one_master', 'one_minion_one_master', 'two_minions_one_master' ]) def test_launch_stop(script_runner, script, virt, config, suite): cmd = (script, '--config', config, '--suite', suite) result = script_runner.run(*cmd) assert result.success assert 'Launching {} ...\n'.format(suite) in result.stderr domains = [] print(virt.getURI()) print(virt.listDomainsID()) for domain in virt.listDomainsID(): print(domain) domains.append(virt.lookupByID(domain).name()) print(str(domains)) # consider refining this assert any('scullery' in domain for domain in domains) result = script_runner.run(*cmd, '--stop') assert result.success assert 'Destroying machines ...\n' in result.stderr domains = [] for domain in virt.listDomainsID(): domains.append(virt.lookupByID(domain).name()) assert not any('scullery' in domain for domain in domains) @pytest.mark.parametrize('config', ['complete'], indirect=True) @pytest.mark.parametrize('suite,masters,minions', [ ('one_minion', None, 'scullery-minion0'), ('two_minions', None, 'scullery-minion0,scullery-minion1'), ('one_master', 'scullery-master0', None), ('one_minion_one_master', 'scullery-master0', 'scullery-minion0'), ('two_minions_one_master', 'scullery-master0', 'scullery-minion0,scullery-minion1') ]) def test_envfile(script_runner, script, config, suite, masters, minions): cmd = (script, '--config', config, '--suite', suite) envfile = '.scullery_env' result = script_runner.run(*cmd, '--env') assert result.success assert os.path.isfile(envfile) envmap = dotenv.dotenv_values(envfile) if masters is not None: assert envmap['SCULLERY_MASTERS'] == masters if minions is not None: assert envmap['SCULLERY_MINIONS'] == minions script_runner.run(*cmd, '--stop') assert os.path.isfile(envfile) is False @pytest.mark.parametrize('config', ['complete'], indirect=True) def test_test_undeclared(script_runner, script, config): result = script_runner.run(script, '--config', config, '--suite', 'one_minion', '--test') assert not result.success assert result.stderr.endswith('Tests requested but not declared in suite configuration\n') @pytest.mark.parametrize('config', ['complete'], indirect=True) def test_test_undefined(script_runner, script, config): result = script_runner.run(script, '--config', config, '--suite', 'one_minion_bogus_test', '--test') assert not result.success assert result.stderr.endswith('Specified test is not defined\n') @pytest.mark.parametrize('config', ['complete'], indirect=True) def test_test_incomplete(script_runner, script, config): result = script_runner.run(script, '--config', config, '--suite', 'one_minion_bogus_test_2', '--test') assert not result.success assert result.stderr.endswith('Incomplete test configuration\n') @pytest.mark.parametrize('config', ['complete'], indirect=True) @pytest.mark.parametrize('suite', [ 'one_minion', 'two_minions', 'one_master', 'one_minion_one_master', 'two_minions_one_master', 'one_minion_bootstrap', 'one_minion_one_master_bootstrap', 'one_minion_salt', 'two_minions_one_master_salt' ]) def test_stop(script_runner, script, config, suite): cmd = (script, '--config', config, '--suite', suite, '--stop', '--force') result = script_runner.run(*cmd) assert result.success def test_stop_success(virt): domains = [] for domain in virt.listDomainsID(): domains.append(virt.lookupByID(domain).name()) assert not any('scullery' in domain for domain in domains) @pytest.mark.parametrize('config', ['complete'], indirect=True) @pytest.mark.parametrize('suite', [ 'one_minion', 'two_minions', 'one_master', 'one_minion_one_master', 'two_minions_one_master' ]) def test_already_stopped(script_runner, script, virt, config, suite): cmd = (script, '--config', config, '--suite', suite, '--stop', '--debug') result = script_runner.run(*cmd) assert result.success assert result.stderr.endswith('DEBUG - main_interactive: Deployment is not running\n') 07070100000008000081A4000000000000000000000001646D49F4000006AE000000000000000000000000000000000000002600000000scullery-0.2/tests/02_test_vagrant.py""" Copyright 2023, Georg Pfuetzenreuter Licensed under the EUPL, Version 1.2 or - as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence"). You may not use this work except in compliance with the Licence. An English copy of the Licence is shipped in a file called LICENSE along with this applications source code. You may obtain copies of the Licence in any of the official languages at https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12. --- Testing functions for Scullery - a SaltStack testing tool. """ import pytest import os from conftest import loadenv import sys @pytest.mark.parametrize('config', ['complete'], indirect=True) @pytest.mark.parametrize('suite', [ 'one_minion_bootstrap', 'one_minion_one_master_bootstrap', ]) def test_bootstrap(script_runner, script, config, suite, vag, testbase): bootstrap_script = '{}/scripts/bootstrap_hello_world.txt'.format(testbase) do_digest = False if sys.version_info[1] > 10: do_digest = True import hashlib with open(bootstrap_script, 'rb') as fh: digest_local = hashlib.file_digest(fh, 'md5') cmd = (script, '--config', config, '--suite', suite) result = script_runner.run(*cmd, '--env') assert result.success assert result.stderr.endswith('main_interactive: Launching {} ...\n'.format(suite)) v = vag v.env = loadenv() assert v.ssh(command='cat /srv/hello_world.txt') == 'Hello world!\n' if do_digest: digest_remote = v.ssh(command='md5sum /srv/hello_world.txt | awk "{ print $1 }"') assert digest_local == digest_remote assert script_runner.run(*cmd, '--stop') 07070100000009000081A4000000000000000000000001646D49F4000006F9000000000000000000000000000000000000002300000000scullery-0.2/tests/03_test_salt.py""" Copyright 2023, Georg Pfuetzenreuter Licensed under the EUPL, Version 1.2 or - as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence"). You may not use this work except in compliance with the Licence. An English copy of the Licence is shipped in a file called LICENSE along with this applications source code. You may obtain copies of the Licence in any of the official languages at https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12. --- Testing functions for Scullery - a SaltStack testing tool. """ import pytest @pytest.mark.parametrize('config', ['complete'], indirect=True) @pytest.mark.parametrize('suite,count', [ ('one_minion_salt', 0), ('two_minions_one_master_salt', 1) ]) def test_salt_test(script_runner, script, config, suite, count): cmd = (script, '--config', config, '--suite', suite) result = script_runner.run(*cmd, '--debug', '--env', '--test') assert result.success for message in [ 'File /srv/hello_world.txt', 'Succeeded: 1', 'DEBUG - main_interactive: state.apply requested', 'INFO - main_interactive: Initiating tests ...', 'DEBUG - runtests: Test result is 0', 'DEBUG - runtests: Test succeeded' ]: assert message in result.stderr assert not any(term in result.stderr for term in [ 'FAILED', 'WARNING - runtests: Tests failed', 'DEBUG - runtests: Test result is 1', 'AssertionError' ]) if count > 0: minions = [0, 1] else: minions = [0] for m in minions: assert 'test_hello_world_content[paramiko://scullery-minion%i] PASSED' % m in result.stdout assert script_runner.run(*cmd, '--stop') 0707010000000A000041ED000000000000000000000002646D49F400000000000000000000000000000000000000000000001B00000000scullery-0.2/tests/configs0707010000000B000081A4000000000000000000000001646D49F400000492000000000000000000000000000000000000002800000000scullery-0.2/tests/configs/complete.ini[box] bootstrap=tests/scripts/bootstrap.sh name=Tumbleweed.x86_64 image=https://download.opensuse.org/repositories/home:/crameleon:/appliances/openSUSE_Tumbleweed/boxes/Tumbleweed.x86_64.json [box.tumbleweed] [box.tumbleweed_bootstrap] bootstrap=tests/scripts/bootstrap_hello_world.sh [box.tumbleweed_salt] bootstrap=tests/scripts/bootstrap_salt.sh [suite.one_minion] minions=1 box=tumbleweed [suite.one_minion_bootstrap] minions=1 box=tumbleweed_bootstrap [suite.one_minion_one_master_bootstrap] minions=1 masters=1 box=tumbleweed_bootstrap [suite.two_minions] minions=2 box=tumbleweed [suite.one_minion_one_master] minions=1 masters=1 box=tumbleweed [suite.one_master] masters=1 box=tumbleweed [suite.two_minions_one_master] minions=2 masters=1 box=tumbleweed [suite.one_minion_bogus_test] minions=1 box=tumbleweed test=cashew [suite.one_minion_bogus_test_2] minions=1 box=tumbleweed test=bogus [test.hello] apply=hello_world test=tests/salt/hello_world/tests/test_hello.py [test.bogus] apply=cashew [suite.one_minion_salt] minions=1 box=tumbleweed_salt test=hello [suite.two_minions_one_master_salt] masters=1 minions=2 box=tumbleweed_salt test=hello 0707010000000C000081A4000000000000000000000001646D49F400000024000000000000000000000000000000000000002B00000000scullery-0.2/tests/configs/missing_box.ini[suite] foo=bar [test.foo] foo=bar 0707010000000D000081A4000000000000000000000001646D49F40000006F000000000000000000000000000000000000003100000000scullery-0.2/tests/configs/missing_box_image.ini[box] bootstrap=scripts/bootstrap.sh [box.tumbleweed] name=mybox [suite.one_minion] minions=1 box=tumbleweed 0707010000000E000081A4000000000000000000000001646D49F4000000E2000000000000000000000000000000000000003000000000scullery-0.2/tests/configs/missing_box_name.ini[box] bootstrap=scripts/bootstrap.sh [box.tumbleweed] image=https://download.opensuse.org/repositories/home:/crameleon:/appliances/openSUSE_Tumbleweed/boxes/Tumbleweed.x86_64.json [suite.one_minion] minions=1 box=tumbleweed 0707010000000F000081A4000000000000000000000001646D49F40000006D000000000000000000000000000000000000002D00000000scullery-0.2/tests/configs/missing_boxes.ini[box] image=https://example.com/example.box [suite.example_suite] minions=1 [test.example] test=example.py 07070100000010000081A4000000000000000000000001646D49F4000000EB000000000000000000000000000000000000003100000000scullery-0.2/tests/configs/missing_suite_box.ini[box] bootstrap=scripts/bootstrap.sh [box.tumbleweed] name=Tumbleweed.x86_64 image=https://download.opensuse.org/repositories/home:/crameleon:/appliances/openSUSE_Tumbleweed/boxes/Tumbleweed.x86_64.json [suite.one_minion] minions=1 07070100000011000081A4000000000000000000000001646D49F400000083000000000000000000000000000000000000002E00000000scullery-0.2/tests/configs/missing_suites.ini[box] image=https://example.com/example.box [box.example] name=ExampleBox file=ExampleVagrantfile [test.example] test=example.py 07070100000012000081A4000000000000000000000001646D49F400000150000000000000000000000000000000000000002400000000scullery-0.2/tests/configs/salt.ini[box] [box.tumbleweed] bootstrap=tests/scripts/bootstrap_salt.sh name=Tumbleweed.x86_64 image=https://download.opensuse.org/repositories/home:/crameleon:/appliances/openSUSE_Tumbleweed/boxes/Tumbleweed.x86_64.json [suite.one_minion] minions=1 box=tumbleweed [suite.two_minions_one_master_bootstrap] minions=2 masters=1 box=tumbleweed 07070100000013000081A4000000000000000000000001646D49F4000000F3000000000000000000000000000000000000003300000000scullery-0.2/tests/configs/undefined_suite_box.ini[box] bootstrap=scripts/bootstrap.sh [box.tumbleweed] name=Tumbleweed.x86_64 image=https://download.opensuse.org/repositories/home:/crameleon:/appliances/openSUSE_Tumbleweed/boxes/Tumbleweed.x86_64.json [suite.one_minion] minions=1 box=leap 07070100000014000081A4000000000000000000000001646D49F4000005D1000000000000000000000000000000000000001F00000000scullery-0.2/tests/conftest.py""" Copyright 2023, Georg Pfuetzenreuter Licensed under the EUPL, Version 1.2 or - as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence"). You may not use this work except in compliance with the Licence. An English copy of the Licence is shipped in a file called LICENSE along with this applications source code. You may obtain copies of the Licence in any of the official languages at https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12. --- Testing functions for Scullery - a SaltStack testing tool. """ import pytest import os import libvirt import vagrant import dotenv @pytest.fixture def script(): is_packaged = False script = 'scullery' if not is_packaged: script = f'{script}.py' return script @pytest.fixture def testbase(): return os.path.abspath(os.path.dirname(os.getenv('PYTEST_CURRENT_TEST'))) @pytest.fixture def config(testbase, request): return '{}/configs/{}.ini'.format(testbase, request.param) @pytest.fixture def virt(): return libvirt.openReadOnly('qemu:///system') @pytest.fixture def vag(): return vagrant.Vagrant(quiet_stderr=False, quiet_stdout=False) def loadenv(): env = os.environ.copy() envmap = dotenv.dotenv_values('.scullery_env') for variable, value in envmap.items(): if value is not None: if isinstance(value, list): value = ','.join(value) env[variable] = value return env 07070100000015000041ED000000000000000000000003646D49F400000000000000000000000000000000000000000000001800000000scullery-0.2/tests/salt07070100000016000041ED000000000000000000000005646D49F400000000000000000000000000000000000000000000002400000000scullery-0.2/tests/salt/hello_world07070100000017000041ED000000000000000000000002646D49F400000000000000000000000000000000000000000000002B00000000scullery-0.2/tests/salt/hello_world/pillar07070100000018000081A4000000000000000000000001646D49F400000020000000000000000000000000000000000000003B00000000scullery-0.2/tests/salt/hello_world/pillar/hello_world.slsgreeting: 'Hello salted world!' 07070100000019000041ED000000000000000000000002646D49F400000000000000000000000000000000000000000000002B00000000scullery-0.2/tests/salt/hello_world/states0707010000001A000081A4000000000000000000000001646D49F400000046000000000000000000000000000000000000003B00000000scullery-0.2/tests/salt/hello_world/states/hello_world.sls/srv/hello_world.txt: file.managed: - contents_pillar: greeting 0707010000001B000041ED000000000000000000000002646D49F400000000000000000000000000000000000000000000002A00000000scullery-0.2/tests/salt/hello_world/tests0707010000001C000081A4000000000000000000000001646D49F400000084000000000000000000000000000000000000003800000000scullery-0.2/tests/salt/hello_world/tests/test_hello.pydef test_hello_world_content(host): assert host.file('/srv/hello_world.txt').content.decode('UTF-8') == 'Hello salted world!\n' 0707010000001D000041ED000000000000000000000002646D49F400000000000000000000000000000000000000000000001B00000000scullery-0.2/tests/scripts0707010000001E000081A4000000000000000000000001646D49F40000001E000000000000000000000000000000000000002800000000scullery-0.2/tests/scripts/bootstrap.shln -s /vagrant /tmp/mysources 0707010000001F000081A4000000000000000000000001646D49F40000002B000000000000000000000000000000000000003400000000scullery-0.2/tests/scripts/bootstrap_hello_world.shecho 'Hello world!' > /srv/hello_world.txt 07070100000020000081A4000000000000000000000001646D49F4000001E4000000000000000000000000000000000000002D00000000scullery-0.2/tests/scripts/bootstrap_salt.shtestbase='/vagrant/tests/salt/hello_world' sls='hello_world.sls' ln -s "$testbase/states/$sls" /srv/salt/ ln -s "$testbase/pillar/$sls" /srv/pillar/ tee /srv/pillar/top.sls >/dev/null <<EOF base: '*': - hello_world EOF if systemctl is-enabled salt-master then count=0 until salt -t10 scullery-\* test.ping do if [ "$count" = 3 ] then logger -s 'No minions connected' break fi echo 'Waiting for minions to connect ...' sleep 5 count=$((count+1)) done fi 07070100000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000B00000000TRAILER!!!103 blocks
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor