Commit Graph

769 Commits

Author SHA1 Message Date
Brian C. Lane 7ad9939fac Cleanup more /tmp/ files when running with --no-virt
Make extra sure anaconda starts with a clean slate.
2018-06-11 16:54:58 -07:00
Brian C. Lane e425b7ccca lorax-composer: Update the yum metadata at startup
Otherwise it can become out of date and depsolving will fail.
2018-06-11 16:54:58 -07:00
Brian C. Lane 2e61bc8bf9 Fix the error responses from lorax-composer
They are now all consistent, returning status 400, including a json
object with status=flase, and an error message inside the error object.
2018-06-11 16:54:58 -07:00
Brian C. Lane 60874d0197 Check to make sure image file exists for /compose/image/
Return an error 400 with an error message if it is missing.
2018-06-11 16:54:58 -07:00
Brian C. Lane dbe9c15ee1 Add UUID prefix to /compose/image/ download filename.
This will make sure it is received as a unique filename, not just
'disk.img' when downloading it.
2018-06-11 16:54:58 -07:00
Brian C. Lane 56766e794f Add support for composer-cli compose commands.
This adds all the commands needed to start, monitor, delete, and
download a compose.
2018-06-11 16:54:58 -07:00
Brian C. Lane 9ba24f305d Add support for modules list, projects list, and projects info 2018-06-11 16:54:58 -07:00
Brian C. Lane d2f784e5da Add composer-cli utility and implement the recipes commands
composer-cli --help shows the commands.
Output defaults to human readable, but raw json can be displayed by
passing --json
2018-06-11 16:54:58 -07:00
Brian C. Lane 79fa1c957e Add ?format=toml support to /recipes/freeze 2018-06-11 16:54:58 -07:00
Brian C. Lane 0ea4eb5206 Fix epoch to ouput an int instead of a str
Also updates the tests.
2018-06-11 16:54:58 -07:00
Brian C. Lane 413964b92f Add ?format=toml support to /recipes/info/
This will return the recipe in TOML format. Note that this does not
include any extra information about errors. Just the recipes, any
unrecognized recipe names will be skipped.
2018-06-11 16:54:58 -07:00
Brian C. Lane 41fd9ab19c lorax-composer: Add partitioned-disk output support
Also add more documentation on lorax-composer, including how to add
support for new output types.
2018-06-11 16:54:58 -07:00
Brian C. Lane 4ae5944567 Add live-iso output support to lorax-composer
This ended up requiring more intrusive changes, but it should be the
most complex of the output types. After moving the core of
livemedia-creator into a function I added more settings to compose_args,
and more defaults to start_build. It now pulls the release information
from /etc/os-release, and produces a bootable .iso
2018-06-11 16:54:58 -07:00
Brian C. Lane 59fd3934f3 Move core of livemedia-creator to run_creator()
We need to be able to share the output types from livemedia-creator with
lorax-composer, so move the core of the main() function into
run_creatoe(). Pass in the cmdline args or a DataHolder with them set.
2018-06-11 16:54:58 -07:00
Brian C. Lane 85ee784efc Only chown recipe directory if it already exists
Since creation of the directory has been moved after switching users
this now needs to check to make sure it exists first.
2018-06-11 16:54:58 -07:00
Brian C. Lane 74326ba7a3 Fix a problem with diff/NEWEST/WORKSPACE
If there is no WORKSPACE yet it was not falling back to using NEWEST.
Also add a test for this.
2018-06-11 16:54:58 -07:00
Brian C. Lane 4144c3937c Check for a source tree doc install first, not second.
This way a source install and test run will always take precedence over
a system installed version.
2018-06-11 16:54:58 -07:00
Alexander Todorov 1f90455ee6 Add required_methods for decorator
otherwise we can't issue OPTIONS requests to the server, see
first comment at http://flask.pocoo.org/snippets/56/
2018-06-11 16:54:58 -07:00
Alexander Todorov 7f7295e3b0 Convert max_age to int b/c timedelta.total_seconds() is a float 2018-06-11 16:54:58 -07:00
Brian C. Lane c399447b81 Fix a problem with using a mirror as the primary url
Because of how Anaconda is run it needs to be passed a baseurl (using
--repo on the anaconda cmdline), not a mirrorlist url. This fixes it so
that the first mirror is used if the main repository is using a
mirrorlist.
2018-06-11 16:54:58 -07:00
Brian C. Lane a1427b1a31 Set the HOME variable to a directory the uid can access
libgit2 will look for $HOME/.gitconfig after dropping root privileges so
this needs to be accessible to the user.
2018-06-11 16:54:58 -07:00
Brian C. Lane 442dc43206 Open the git repo after dropping root privileges
Also make sure the recipe directory and its contents have correct
ownership, and change the default recipe path when using the systemd
service to /var/lib/lorax/composer/recipes/
2018-06-11 16:54:58 -07:00
Brian C. Lane 4ae2e1450d Exit on uid/gid errors before checking directory permissions
If the uid/gid check fails there is no sense in trying to examine the
ownership or permissions.
2018-06-11 16:54:58 -07:00
Brian C. Lane daa5ed2aaf Add documentation for /compose and /compose/types 2018-06-11 16:54:58 -07:00
Brian C. Lane eb2a7208c8 Move queue monitor startup into a function
This allows it to be used by the test framework.
2018-06-11 16:54:58 -07:00
Brian C. Lane 63a7897457 Move queue directory creation into a function
So that it can also be used during tests
2018-06-11 16:54:58 -07:00
Brian C. Lane 8da6214e10 Add a test mode to /compose
This will allow testing without having a full system setup with
anaconda, if ?test=1 is passed to the POST /compose command it will wait
10 seconds instead of running Anaconda, and then raise an error to
generate a failed build.

Passing ?test=2 will also wait 10 seconds instead of running Anaconda,
but will finish successfully.
2018-06-11 16:54:58 -07:00
Brian C. Lane 2e1e8c20c7 Cleanup docstrings for queue.py 2018-06-11 16:54:58 -07:00
Brian C. Lane 9603c866af Drop cancel_q from the monitor() function
Not needed, builds are canceled by writing a 'CANCEL' file in the results
directory.
2018-06-11 16:54:58 -07:00
Brian C. Lane 166350fcb6 Fix the jsonify calls to use kwargs
No need to pass it a dict, just set the args.
2018-06-11 16:54:58 -07:00
Brian C. Lane ff7d36bcbc Add /compose/log/ API to retrieve the end of the build log
This allows the client to request the end of the anaconda.log during and
after a build. The amount of data returned can be set by adding
?size=<kbytes>

Output is raw bytes, starting on the next available line boundry.
2018-06-11 16:54:58 -07:00
Brian C. Lane caee8e7cdf Return a status of false if the uuid isn't valid 2018-06-11 16:54:58 -07:00
Brian C. Lane 072aa720ff Add /compose/cancel API to cancel a running build
If the build hasn't started yet (state is WAITING) try removing the
symlink to it. If this succeeds, delete the partial results directory.

If the build makes it to RUNNING then it writes a CANCEL file in the
results directory. The callback that is passed to execWithRedirect
catches this, causing a SIGTERM to be sent to anaconda. It then exits
and cleanup happens normally. The partial results directory is then
removed.
2018-06-11 16:54:58 -07:00
Brian C. Lane 8f0bca00c0 Pass the callback_func through novirt_install to execWithRedirect
The default is no callback.
2018-06-11 16:54:58 -07:00
Brian C. Lane f1d8b10867 Add a callback to execWithRedirect
If the callback returns true send the process a SIGTERM to terminate it.
2018-06-11 16:54:58 -07:00
Alexander Todorov 32db249538 Add tests for yumbase and update how we inspect boolean options
.get_default() returns string so make sure we're actually parsing
the value as boolean and not evaluating a non-empty string in a
boolean context (which will always return True)
2018-06-11 16:54:58 -07:00
Brian C. Lane 6a95a314e9 Add API routes for downloading build results
Also fix a bug with the name of the queue status in the status results
(it is now 'queue_status' not 'status' which is used for error
responses).

This adds the following routes:
 - /compose/metadata/<uuid> to retrieve a .tar of the build metadata
 - /compose/results/<uuid> to retrieve .tar of all of the build results
 - /compose/logs/<uuid> to retrieve a .tar of just the logs from the build
 - /compose/image/<uuid> to retrieve the output image from the build
2018-06-11 16:54:58 -07:00
Brian C. Lane ed03ac7524 Add /compose/info route to retrieve details about a compose
The results is a JSON string with the following information:

* id - The uuid of the comoposition
* config - containing the configuration settings used to run Anaconda
* recipe - The depsolved recipe used to generate the kickstart
* commit - The (local) git commit hash for the recipe used
* deps - The NEVRA of all of the dependencies used in the composition
* compose_type - The type of output generated (tar, iso, etc.)
* queue_status - The final status of the composition (FINISHED or FAILED)
2018-06-11 16:54:58 -07:00
Brian C. Lane d3a9ec3002 Return the commit id for the recipe being read
This adds returning the commit id from read_commit, and a new function
read_recipe_and_id() that returns the commit id and the recipe in a
tuple.

If the commit is passed in, it is used as is. If no commit is passed in
it finds the most recent commit for the file on the selected branch and
returns that.

Missing recipes now raise a RecipeError with an informative message.
eg. "No commits for missing-recipe.toml on the master branch."
2018-06-11 16:54:58 -07:00
Brian C. Lane 22c03ceba7 Fix yum config directory creation for projects and server tests 2018-06-11 16:54:58 -07:00
Brian C. Lane b99a7756de Add DELETE /compose/delete/<uuids> API route
This will delete all of the build's results and cannot be undone.
2018-06-11 16:54:58 -07:00
Brian C. Lane 3fdf3a9819 Turn on o+x permission for the queue and results directories
Otherwise it won't allow a group member to delete things.
2018-06-11 16:54:58 -07:00
Brian C. Lane fdcf839753 Add /compose/status/<uuids> to retrieve details of a specific build 2018-06-11 16:54:58 -07:00
Brian C. Lane 91c6d1525d Add compose status routes /compose/finished and /compose/failed
These will return a list of details about the finished or failed builds.
2018-06-11 16:54:58 -07:00
Brian C. Lane 520177afca Add /compose/queue to get the status of the build queue
This will return a JSON result that includes the waiting builds,
and the running builds.
2018-06-11 16:54:58 -07:00
Brian C. Lane 47f21af7fb Add reading a recipe directly from a file
Adds helper function recipe_from_file to recipes.py
2018-06-11 16:54:58 -07:00
Brian C. Lane 0065cadf2d Include the recipe in the results of a build
Write original as recipe.toml and the depsolved version as frozen.toml

Also write 'WAITING' to the STATUS file as its first state.
The STATUS states are now WAITING -> RUNNING -> FINISHED|FAILED
2018-06-11 16:54:58 -07:00
Brian C. Lane 9fc973366f Move creating a frozen recipe into recipes.py
Also adds .package_names and .module_names properties. Call
recipe.freeze with a list of NEVRA dependencies and it will return a new
Recipe object with all of the packages and modules set to the depsolved
version.
2018-06-11 16:54:58 -07:00
Brian C. Lane 67da4d6971 Add building an image, and the /compose route to start it
This adds the ability to build a tar output image. The /compose and
/compose/types API routes are now available.

To start a build POST a JSON body to /compose, like this:

{"recipe_name":"glusterfs", "compose_type":"tar", "branch":"master"}

This will return a unique build id:

{
  "build_id": "4d13abb6-aa4e-4c80-a671-0b867e6e77f6",
  "status": true
}

which will be used to keep track of the build status (routes for this
do not exist yet).
2018-06-11 16:54:58 -07:00
Brian C. Lane de9f5b0456 Remove test configuration and read it from the build directory 2018-06-11 16:54:58 -07:00
Brian C. Lane 7372faa969 Add function to return full NEVRA of a dependency 2018-06-11 16:54:58 -07:00
Brian C. Lane c92373ecd6 Change config and paths
With the API running as weldr the permissions on the yum directories
needs to be accessable to it, as well as the results and queue/new
directories.
2018-06-11 16:54:58 -07:00
Brian C. Lane e2f4674fb3 Add basic composer queue handling
The queue is in /var/lib/weldr/queue/new by default. It watches the
directory for new symlinks (to /var/lib/weldr/results/<dirname>) and
handles running anaconda on the kickstart found in final-kickstart.ks
inside the symlinked directory.
2018-06-11 16:54:58 -07:00
Brian C. Lane 0ce4197a1e Change compress to use communicate instead of wait
Also move default_image_name into imgutils so it can be used in other
places.

When running from lorax-composer the wait() call wasn't waiting until
the tar was finished. I think this is due to gevent monkey-patching
something. Using communicate() solves this problem.
2018-06-11 16:54:58 -07:00
Brian C. Lane 57d9d40c29 Add documentation for the API routes.
Use Sphinx on a CentOS7/RHEL7 system to generate the docs with 'make docs'
2018-06-11 16:54:58 -07:00
Brian C. Lane 377f5e4124 Switch the API to use a Unix Domain Socket
This drops support for the TCP port and switches to using a socket at
/var/run/weldr/api.socket

Also add the start of some docs for lorax-composer.

--host and --port argument have been removed.

--group sets the group name to use for access to the socket and its
parent directory. Defaults to 'weldr'

--socket sets the full path to the socket to create. Defaults to
'/var/run/weldr/api.socket'
2018-06-11 16:54:58 -07:00
Brian C. Lane 916a001d73 Add support for other branches to the routes
Passing ?branch=<branch-name> will use the specified branch instead of
master.

The new branch will not exist until a /recipes/new?branch=new-branch
POST is made. At that time the branch will be created based on the
current master branch and the new commit will be added to it.
2018-06-11 16:54:58 -07:00
Alexander Todorov 0af072c77e Silence pocketlint bad-preconf-access warnings 2018-06-11 16:54:58 -07:00
Martin Pitt 176b12dd8c Fix depsolving empty recipes
- Fix `projects_depsolve()` to not consider a successful empty response
   (rc == 0) as an error.
 - Fix recipe_from_dict() to default modules and packages to empty lists
   instead of `None`, to avoid a Python-ism in the API for consumers and
   stay compatible to the bdcs API.

Fixes #290
2018-06-11 16:54:58 -07:00
Martin Pitt da3616db72 Fix wrong function name in api/v0/recipes/freeze error messages 2018-06-11 16:54:58 -07:00
Brian C. Lane 3e5c0707bb Redirect yum's logging to yum.log 2018-06-11 16:54:58 -07:00
Brian C. Lane a44e499eee Close the rpmdb after every API operation.
rpm blocks all of the signals until closeRpmDB() is called.
We need to call it after all of the API calls.
2018-06-11 16:54:58 -07:00
Brian C. Lane cf42e1a480 Fix error string when there is a problem listing projects 2018-06-11 16:54:58 -07:00
Brian C. Lane efd15aaad7 Add --releasever option to lorax-composer
If it isn't set the releasever value will use yum and the system / to
find the releasever.
2018-06-11 16:54:58 -07:00
Brian C. Lane bae551b7ab Add filtering and glob support to /modules/list route 2018-06-11 16:54:58 -07:00
Brian C. Lane 6b4bf92e7f Add /recipes/freeze route and tests. 2018-06-11 16:54:58 -07:00
Brian C. Lane b8212358bc Add /recipes/depsolve route and test 2018-06-11 16:54:58 -07:00
Brian C. Lane a85d0ced8b Add /projects and /modules API tests 2018-06-11 16:54:58 -07:00
Brian C. Lane 164232ba4d Modify pylorax.api.config.configure so it can also be used for tests. 2018-06-11 16:54:58 -07:00
Brian C. Lane ad5ab71551 Move ComposerConfig into pylorax.api.config module 2018-06-11 16:54:58 -07:00
Brian C. Lane 8fee86a5db Catch ProjectsError and return an error 400 with a message. 2018-06-11 16:54:58 -07:00
Brian C. Lane a1e7e4831d Catch Yum errors in the projects functions 2018-06-11 16:54:58 -07:00
Brian C. Lane 23d90ec066 Add /modules/list and /modules/info routes 2018-06-11 16:54:58 -07:00
Brian C. Lane 8635a59ac7 Add modules functions and update function documentation 2018-06-11 16:54:58 -07:00
Brian C. Lane c3d495fe53 Add /projects/depsolve route 2018-06-11 16:54:58 -07:00
Brian C. Lane 99140b98b9 Add /projects/info route
Elements that have no match in yum (metadata) are set to empty dicts.
2018-06-11 16:54:58 -07:00
Brian C. Lane 0819e97646 Add /projects/list route 2018-06-11 16:54:58 -07:00
Brian C. Lane 105679d79d Add /api/v0/test route
Returns a simple string to indicate that the API server is running.

/api/v0/status should be used instead, it provides more detailed info in
JSON format.
2018-06-11 16:54:58 -07:00
Brian C. Lane 569ce1d3dc Add support for yum to lorax-composer
This includes a new configuration file at /etc/lorax/composer.conf with
built-in defaults. It also adds a YUMLOCK server config object so that
request handlers can access the yum base object without interfering
with each other.
2018-06-11 16:54:58 -07:00
Brian C. Lane 5d6c236af6 Add /api/docs to serve up the documentation
This requires that the docs be at /usr/share/doc/lorax-*/html/ or if
running from the source tree, at ./docs/html/

They can be re-created by running 'make docs'
2018-06-11 16:54:58 -07:00
Brian C. Lane 1d53d00532 Add limit/offset to recipes/list 2018-06-11 16:54:58 -07:00
Brian C. Lane 2cd4fcfd88 Add error message for offset/limit type errors 2018-06-11 16:54:58 -07:00
Brian C. Lane 9ca9bfe46f Add error logging to api/v0.py
These will end up in the /var/log/lorax-composer/composer.log
2018-06-11 16:54:58 -07:00
Brian C. Lane 950d9df217 Fix server request logging.
And switch the other logs to append instead of overwrite on each run.
2018-06-11 16:54:57 -07:00
Brian C. Lane 453082ab9f lorax-composer: Drop unneeded parameters and create missing directories
The log directory (and parents) will be created if they are missing.
An empty recipe directory will be created if it doesn't exist.
2018-06-11 16:54:57 -07:00
Brian C. Lane d701120d90 Add /recipes/diff route and tests 2018-06-11 16:54:57 -07:00
Brian C. Lane 052a8ba991 Add recipe_diff function and helpers.
This takes a pair of Recipe objects and returns a list of diff dicts
that include what was changed between the two recipes.
2018-06-11 16:54:57 -07:00
Brian C. Lane a76e95dcb5 Add POST /recipes/tag/ route and tests 2018-06-11 16:54:57 -07:00
Brian C. Lane 7f1adf120c Add tag_recipe_commit helper function
And change tests to use it so that both it and tag_file_commit are used.
2018-06-11 16:54:57 -07:00
Brian C. Lane 3f4140d5d3 Add POST /recipes/undo route and tests 2018-06-11 16:54:57 -07:00
Brian C. Lane 639d325a0c Change read_recipe_commit to use the recipe name
Callers really shouldn't need to know the details of the filenames, so
change it to convert it internally.
2018-06-11 16:54:57 -07:00
Brian C. Lane ab6decec0b Add revert_recipe function
And adjust the tests to use it so that it covers both revert_recipe and
revert_file.
2018-06-11 16:54:57 -07:00
Brian C. Lane c294b7747d Add DELETE /recipes/delete/<recipe_name> route and tests
Also add numbering to the tests so that they are executed in the
expected order.
2018-06-11 16:54:57 -07:00
Brian C. Lane c937e69d3b Add delete_recipe helper function and test
Use delete_recipe in the test so that both it and delete_file are
covered.
2018-06-11 16:54:57 -07:00
Brian C. Lane 6e453e70dc Add DELETE /recipes/workspace/<recipe_name> route and tests
This will delete the workspace copy of the recipe.
2018-06-11 16:54:57 -07:00
Brian C. Lane 72b4c4fe28 Add POST /recipes/workspace route
Also fix use of workspace in /recipes/info (was using filename instead
of recipe name and logic for changed was backwards).
2018-06-11 16:54:57 -07:00
Brian C. Lane 711cdf53b3 Add /recipes/new route and tests
This handles json data when the mime type is "application/json" and toml
recipes when it is "text/x-toml"
2018-06-11 16:54:57 -07:00
Brian C. Lane 7b5115d19c Split recipe_from_toml into recipe_from_dict helper.
This will be useful for creating Recipe objects from json created dicts.
2018-06-11 16:54:57 -07:00
Brian C. Lane 3c75711b30 Fix the recipe version bumping
Recipe should have its version bumped based on the version from the
previous commit, and not be bumped on the first commit. Fix the code and
the tests.
2018-06-11 16:54:57 -07:00
Brian C. Lane 02db2afb2b Add /recipes/changes route with tests. 2018-06-11 16:54:57 -07:00