Commit Graph

287 Commits

Author SHA1 Message Date
Andreas Jaeger e88f6b747a Retire craton
Remove everything, add a README with explanation.

Change-Id: I7c8fcfac0d904f144b6a3838d25db0987d1e74a5
2018-01-18 15:22:28 +01:00
Jim Baker 555d0c8856 Updates Alembic migration to better match SQLAlchemy models
The original Alembic migration script was autogenerated, then
subsequently modified by hand. Between these two aspects, some
correspondence to the corresponding SQLAlchemy models was lost:

* Columns were specified independently of corresponding foreign key
  and primary key constraints; besides making it more difficult to
  follow the code between models and the migration script, there was a
  loss of integrity constraints: a variable association must exist for
  every entity that mixes in VariableMixin as a base was not being
  enforced at the database level with an appropriate not-null; this
  causes problems for use of variables for any such object that is not
  constructed by models code, most notably via direct usage of the
  database. (See specifically
  https://bugs.launchpad.net/craton/+bug/1668251, fixed with this
  change.)

* The column created_at would always be set by model-using code; but
  this was not enforced at the database level by ensuring it was not
  null.

* Children should be deleted if the parent is deleted (we do not
  support "soft delete" in Craton).

In addition, all constraints are now named (the original intent of
this change, so as to ensure the feasibility of future migrations),
and they are also named in a consistent fashion.

Note that this change does not support many-to-many deletions (as seen
in https://bugs.launchpad.net/craton/+bug/1668308), but SQLAlchemy
does provide support for this at the model level. A future change can
address this without requiring Alembic support.

There's no direct testing of this change, but it is implicitly, and
rather strongly, tested by the overall functional tests that are used;
and to a lesser extent by some of the unit tests. This is in part
because this change has strengthened constraints, not weakened them.

Change-Id: I1f84c29610127de12c292a210fd003ae07bd6462
Closes-bug: 1665066
Closes-bug: 1668251
2017-03-29 14:11:45 -06:00
Thomas Maddox 606926b89d JSON Path-like querying for variables
This patch implements the ability to query for values
in nested variable documents. For instance, if we had
hosts with a variables that look like:

{
    "hardware_profiles": {
        "disks": [
            {
                "manufacturer": "seagate",
                "capacity_quantity": 2,
                "capacity_unit": "TB"
            },
            {
                "manufacturer": "western",
                "capacity_quantity": 3,
                "capacity_unit": "TB"
            }
        ]
    }
}

and we wanted to grab all of them with a disk that was
manufactured by Seagate, we would like to be able to
query like so:

GET /v1/hosts?vars=hardware_profiles.disks[*].manufacturer:"seagate"

This does modify the variables query to expect valid JSON
values. So, strings need to be quoted, for instance.

Change-Id: Id597d3e57d2e28766fecd1b314f53176543e1b9d
Closes-Bug: 1671116
2017-03-28 15:23:52 +00:00
Jenkins 0e4280ede3 Merge "Ensure JSON responses result from failure" 2017-03-28 04:51:31 +00:00
git-harry 533492b4d3 Ensure JSON responses result from failure
Responses generated from failure should be JSON formatted.

flask_restful.Api is subclassed to control the format of all error
responses generated by the API Flask app.

The API middleware is modified to use the same error response function
given that it is not part of the Flask app for the API. Any Response
object created by the middleware has been converted to an exception to
ensure that all error responses are generated using the same code.

The use of abort has been replaced with raising exceptions, this further
consolidates the error response mechanism.

response_filter has been modified so that it always expects to receive a
response tuple now that http_codes is no longer there to return a
response object.

The error filters in schemas.py have been removed. These were not used
by the existing code.

Closes-bug: 1665015

Change-Id: I2be40e9493f313b3fe0173c34d371659039c1bae
2017-03-27 22:18:39 +01:00
Thomas Maddox 1e1e8da171 Return variables in response on Network Device create
If a user creates a network device and also passes
variables during the create process the variables
get created but are not present in the response.

This patch fixes that by adding variables in response
for a create calls on network devices when variable
was in the create request body.

Change-Id: Id9818d5c30a9a0c17039191335f1b75525003a3d
Closes-Bug: 1675087
2017-03-22 16:50:34 +00:00
Jenkins 6eaa61ccc0 Merge "Create user under project_id passed in request" 2017-03-22 14:08:17 +00:00
Sulochan Acharya 5f0e8d7622 Create user under project_id passed in request
Currently when user is created, its taking the project_id
parameter from the user who is creating the request.
However, given root users are expected to be ablet to create
users for all projects this patch modifies the behaviour
and ensure that the user creation is always under the
project_id parameter that is passed in.

Functional test for create call is added. However,
function test coverage is not complete. It needs to
be addressed as a separate commit, tacked in
issue: 1674287

Closes Bug: 1666695
Partial-Bug: 1674287
Parent: Ie5fac9ef4c305ff7e67fe32855ca8100a8adfa82

Change-Id: I19fb901ad41edeeb0a92f41264867a768a207fce
2017-03-22 11:32:41 +00:00
Jenkins 637250ee6a Merge "Move to MySQL 5.7 and SQLAlchemy>=1.1.0" 2017-03-21 21:41:45 +00:00
Jenkins 2fe08e9f4c Merge "Return variables in response on Network create" 2017-03-21 21:41:14 +00:00
Jenkins 1d9e1b1b86 Merge "Remove log translations" 2017-03-21 21:24:15 +00:00
Thomas Maddox 6884f8ff8c Move to MySQL 5.7 and SQLAlchemy>=1.1.0
In an effort to support JSON Path variable
queries, we need to:
* Pin to MySQL 5.7
* Use JSON column type
* Use a newer SQLAlchemy library.

Change-Id: I98ae021c9cd9755f51e67e56135db164e8ae1f50
Partial-Bug: 1671116
Depends-On: I36b7ae9cf68aeef0e5dbcb1f17db52b81efd6ffe
2017-03-21 21:22:55 +00:00
Thomas Maddox 5852565dcd Return variables in response on Network create
If a user creates a network and also passes variables
during the create process the variables get created
but are not present in the response.

This patch fixes that by adding variables in response
for a create calls on networks when variable was in
the create request body.

Change-Id: I2320f5b07d3544286234ecc5b1cee4eea999b59e
Closes-Bug: 1674815
2017-03-21 21:21:13 +00:00
Jenkins 12b31e49ac Merge "Variable search for resources now uses resolved variables." 2017-03-21 16:41:38 +00:00
Jim Baker 3d0506b69c Variable search for resources now uses resolved variables.
Implements a filter addition for vars such that each key-value pair in
the vars is searched for a possible match, regardless of associated
resource; then chases the associated resources for the specific
resource being searched for, thereby implementing the resolution
algorithm (but in reverse). Finally all such resources are checked to
see if they intersect with respect to their rooting key-value pairs in
the original search.

Examples:

$ GET v1/hosts?vars=openstack_release:juno

$ GET v1/hosts?vars=foo:abc,bar:xyz

To disable this feature in your request, you can supply
'resolved-values=false', for example:

$ GET /v1/hosts?vars=foo:bar,baz:zoo&resolved-value=false

Filter values are not currently encoded for JSON; but this will fixed
in a subsequent patch that is addressing generalized JSON matching via
JSON path.

Change-Id: I1d40d734e60b5563dfb01da05ffb6494ed9a919c
Closes-bug: 1661226
Closes-bug: 1669493
2017-03-21 13:45:13 +00:00
Tao Li fda7af32fa Remove log translations
Log messages are no longer being translated. This removes all use of the
_LE, _LI, and _LW translation markers to simplify logging and to avoid
confusion with new contributions. See:
http://lists.openstack.org/pipermail/openstack-i18n/2016-November/002574.html
http://lists.openstack.org/pipermail/openstack-dev/2017-March/113365.html

Change-Id: I9d94735ace6f0dde822bfb37e5c94195a010d837
2017-03-21 16:03:41 +08:00
Sulochan Acharya 9ddf2c4cd5 Include project_id only where needed
Currently project_id is allowed in request body
for all request, however, its not honered since project_id
is pulled from headers.

This commit separates the need for project_id only where
its needed. For instance, in users we expect project_id
to allow creating users for different projects or we
expect project_id in response body.

Partial-Bug: 1666695

Change-Id: Ie5fac9ef4c305ff7e67fe32855ca8100a8adfa82
2017-03-20 09:33:59 +00:00
Jenkins 667ac16008 Merge "Adds project/user bootstrap command to dbsync" 2017-03-13 20:48:06 +00:00
Sulochan Acharya 109b4b6dd2 Adds project/user bootstrap command to dbsync
So far we have been using external mysql command
to insert project/user to bootstrap the process.
This caused much frustration since operators needed
to insert records in the db. This patch adds commands
to dbsync to allow creating project/users. This method
also takes care of association_id.

To initiate a bootstrap:
craton-dbsync --config-file=craton.conf bootstrap

which will create a project with a root user.

Users using Dockerfile can look at docker logs
after creating the container to find this info.

Closes Bug: 1670561

Change-Id: I9372961ca6623d530d7844b9f38aade544d961e8
2017-03-13 20:30:03 +00:00
git-harry a690e1997c Validate parent_id is neither id nor a descendant
A device's parent_id represents the id of another device. A parent_id
cannot be a device's own id nor can it be the id of a descendant.

This commit adds a validator decorator to ensure that the parent_id
supplied meets the requirements before the database is updated. Failure
to properly validate the parent_id can cause the database to become
unresponsive.

If an invalid parent_id is supplied the API will return a 400 Bad
Request.

Change-Id: I81f6bff5bf64b7c441fef08a8e03731cc17bb2f1
Closes-bug: 1666536
2017-03-09 10:45:43 +00:00
git-harry cbb246111b Add http_codes decorator where missing
This commit adds the decorator http_codes to a number of the API put
methods so that all now use it. This ensures any exceptions generated by
the methods return the expected status code and the response body is
JSON encoded.

Change-Id: Id24ef3687afe21e36adae225efdef7150b5d5318
Partial-bug: 1665015
2017-03-09 09:16:51 +00:00
git-harry 0f7ee6d791 Pretty-print format all JSON response bodies
Flask-RESTful automatically converts a response body to JSON when it
creates the Response object. The Flask app configuration option
RESTFUL_JSON is added by this commit to appropriately modify how the
JSON body is constructed.

response_filter has been modified so that it returns a tuple of
information that Flask-RESTful will use to create an appropriately
formatted response.

Resource.error_response is creating the Response object itself and so
has been modified to format the JSON in the same way as Flask-RESTful.
Ideally, error_response would not create a separate Response object
however addressing this is a separate issue.

Change-Id: I02eafaf48d7c6e2ceab0add2f78cf6aa1b890f18
Closes-bug: 1664328
2017-03-07 15:57:46 +00:00
git-harry 61a805b185 Remove networks validation duplicate details key
This commit consolidates the values of a duplicate key and removes the
duplicate.

Change-Id: I0b955fe52c9471de09f8a73fe95961037c570653
2017-03-06 16:03:06 +00:00
Jenkins 8570377429 Merge "Allow resolved vars in details list calls" 2017-03-03 19:19:26 +00:00
sulochan acharya 1d3fcad786 Allow resolved vars in details list calls
Currently the details=all flag allows us to only
get local variables. This changes that to be resolved
variables such that it matches the rest of the variables
calls.

It also adds details calls to /clouds and /projects
endpoints where it was missing.

Closes Bug: 1667767

Change-Id: Ia2de9110aa118c3fe7cd9374ceed2ce74f13c74e
2017-03-03 11:10:47 +00:00
Jenkins 39683822da Merge "Move craton to a non-conflicting port" 2017-03-03 09:55:30 +00:00
Ian Cordasco bb4304eeee Update schema definition for network interfaces port
Previously, listing or creating a network interface required the port be
an integer. Updating the port, however, allowed it to be a string
instead of similarly requiring it to be an integer. This updates the
constraint and adds the basis of functional testing for those endpoints.

Closes-bug: #1630276
Change-Id: Ic99d73dfd63fb3fe9a64d41ca2b8eafe4ff1c253
2017-03-02 08:28:28 -06:00
Kevin Carter d464139d34
Move craton to a non-conflicting port
This change moves craton to a port that is not in use according to
/etc/services and is not being consumed by any other OpenStack service
as defined here: [
https://docs.openstack.org/newton/config-reference/firewalls-default-ports.html
].  This should allow other deployers to leverage craton in an way that
does not conflict with other OpenStack services already running in
production.

Change-Id: I2d0432b4c608cf11538d7b8f267eaf7be763204c
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
2017-03-01 17:30:22 -06:00
sulochan acharya a16a0b0a42 Enable vars resolution in cells and regions
We were only using resolved vars in hosts/devics.
However, given the new structure where we have a
cloud -> region -> cell -> host ... it makes sense
to have top level vars on cloud level. This patch
therefore enables variable resolution on regions and
cells now.

Closes Bug: 1669038

Change-Id: I9f4c7dbce0082b1ce0b1f03460c51e39b7a12309
2017-03-01 16:42:26 +00:00
Thomas Maddox ddc1807338 Require region_id and cloud_id for POST /networks
This patch corrects the schema to include requirements
for region_id and cloud_id when creating a network.

Change-Id: I0edbf5efa51a55c425051cbe8d7a60c6ed0a2232
Closes-Bug: 1661761
2017-02-26 16:17:55 +00:00
Thomas Maddox b4cd6d35b3 Add Cloud resource before Region
This patch includes the Cloud resource to allow
for a project o have multiple clouds under it. This
modifies the environment hierarchy to look like:
Project -> Cloud -> Region (-> Cell) -> ...

Change-Id: Ib1c16a504430760f2a7234221f91429a7ea72596
Closes-Bug: 1662576
2017-02-24 20:38:18 +00:00
Jenkins 3952075a37 Merge "Allow getting vars on get all resouce call" 2017-02-24 18:15:34 +00:00
Jenkins 5c231190a7 Merge "Add GET /v1/devices" 2017-02-24 17:43:33 +00:00
git-harry f9724d3b91 Add GET /v1/devices
This commit adds support for a devices endpoint to allow the listing of
heterogeneous collections of devices. This complements the hosts and
network-devices endpoints that only allow the listing of devices of
their respective types.

The devices endpoint supports the query parameter "descendants", this
allows the user to choose whether or not a query includes the
descendants of a specified parent_id. For example
'/v1/devices?parent_id=3&descendants=true' would return any devices with
a parent_id of 3 as well as any descendants of those devices.

The devices DB model has been extended to include a descendants property
to allow a device's descendants to be determined.

The functional testing database clean-up has been modified to enable to
tables to be deleted when devices have been given parent_id's.
create_region and create_host methods have been moved to the base
TestCase class to prevent duplicating this code in the new tests.

Change-Id: Ia6f8dca6cbbf3d583bdff69559be0e803d2cf6de
Co-Authored-By: Jim Baker <jim.baker@python.org>
Implements: bp/list-devices
2017-02-24 17:22:07 +00:00
Sulochan Acharya 2a5f24fa7d Allow getting vars on get all resouce call
- This patch adds a new parameter `details` as query
parameter such that, when doing a list call on any
resource we can do ?details=all to get the variables
associated with the particualr resource.

Closes Bug: 1662618

Change-Id: Ic8423e30ca05d265ca6419fa179d5569a1995e3e
2017-02-24 14:59:31 +00:00
Sulochan Acharya 78136334da Ensures no extra property is allowed on creates
Currently we have validators and filters that ensure
certain propeties on GET/POST/PUT calls. So far we
have been using the same schema for GET and POST calls
as a result it was possible to post id, created_at etc
when creating resources. This patch fixes this by dividing
the schema to match get and creates.

This adds black listed properties on creates, which can
be expanded according to the resource in question in the
future in needed.

Functional tests are addded.

Closes Bug: 1662848

Change-Id: I9226c18187064b310c811164e146da4909295768
2017-02-24 10:10:55 +00:00
Ian Cordasco 1a4f4392c4 Add support to regions for sort_dir and sort_keys
This also refactors how we add pagination related query parameters to
each schema set of request args.

Closes-Bug: 1667027
Change-Id: Iecb628f05de02d1a153b3b63ab6dd67c33c53053
2017-02-22 13:26:20 -06:00
Jenkins f398eb8fc7 Merge "Use String for Project ID in schema" 2017-02-22 19:00:03 +00:00
Jenkins 6da5fd3712 Merge "Ignore None param values when generating links" 2017-02-22 18:59:04 +00:00
Thomas Maddox 95c61074fb Use String for Project ID in schema
This patch sets the schema to accept a string
for Project ID since it's actually a UUID

Change-Id: Iad8733594ca83c3bc061017fd9eae6861f31ee5d
Closes-Bug: 1665780
2017-02-22 11:59:09 -06:00
Thomas Maddox a20172dd3c Ignore None param values when generating links
This patch includes a branch to tell _link_params_for
to skip params that have a None value when generating
its links.

Change-Id: I6182028dec94b010ea79a0f281f17d3f70f3b202
Closes-Bug: 1665779
2017-02-22 09:51:52 -06:00
Sulochan Acharya a1ce937f26 Fixes device search by label
- After commit aad5fd33c3
search for host devices by label was broken because the
pagination function was unable to handle joins on relationsip.

This patch switch to filter rule on query so that it plays
nice with the pagination patch.

Unit test on db and functional tests are added to test
filtering by label.

Closes-Bug: 1662842
Change-Id: I476a5efcc1e5ef8735833dd37583653f2c9d56c5
2017-02-21 16:04:42 +00:00
Ian Cordasco 462c501b13 Add sort_dir and sort_keys to endpoint schemata
sort_dir and sort_keys are used in the pagination work. Adding them to
the schemata allows users to specify them in their queries without
receiving 400 Bad Request errors.

Change-Id: If743958afc578be0ffa48c9b0a2670f76855424c
Partial-Bug: #1664786
Implements: bp pagination-of-resources
2017-02-17 12:17:28 -06:00
Jenkins fe2cc0e651 Merge "Configure OpenStack CI to run functional tests" 2017-02-17 17:07:56 +00:00
Ian Cordasco 65c6f941e1 Configure OpenStack CI to run functional tests
For our default CI jobs, we can add a test-setup.sh script that will run
before OpenStack CI revokes sudo for the "jenkins" user.

At the moment, we cannot add the jenkins user to the docker group to
allow the jenkins user to use docker. Instead, we have to make docker
launch itself so that the jenkins group can access the socket.

Change-Id: I732d144e4635dffe8034c0d374eee591df078f52
2017-02-17 10:17:44 -06:00
Jenkins c7dda3fb51 Merge "RBAC-Lite for generic resources implementation" 2017-02-17 13:51:57 +00:00
Thomas Maddox bf1cdf4740 RBAC-Lite for generic resources implementation
This patch re-applies RBAC-lite to the /projects
endpoint. For the top-level /projects endpoint,
permissions have been narrowed to only root
project users. Anything pertaining to a specific
project has been narrowed to project admin users.

This patch implements a decorator to afford us the
same features for the generic resources functions
that @require_project_admin_context and
@require_admin_context decorators afforded us
piecemeal for other DB API functions.

Change-Id: I875a9a8cb68c76d27f613bac6f4b87f3a1e2b411
Closes-Bug: 1665237
Closes-Bug: 1648626
2017-02-16 20:29:03 +00:00
Thomas Maddox 01acb6449d Removes left-over debugging logs
This fix removes some left-over debug statements
that made it through gate on accident.

Change-Id: I95f0f9f20704c0f05b8f2c280e579b6064d4f89f
Related-Bug: 1648626
2017-02-16 14:30:22 +00:00
Jenkins e37a88636e Merge "Adds Variables support to Projects resource" 2017-02-16 01:06:32 +00:00
Ian Cordasco 603cef7a31 Adds Variables support to Projects resource
Includes Variables support, which is already present
in several other Craton resources, in the Projects
resource as well.

Project variables will serve as a top-most scope
of variables for resources that belong to a specific
project.

Partial-Bug: 1648626
Closes-Bug: 1661670

Change-Id: I574e834ce409efd8ceafb15fe30a86ae93df2a80
2017-02-15 23:56:18 +00:00