Commit Graph

16 Commits

Author SHA1 Message Date
Radosław Piliszek 77464a1385 Finish switch from http.client to HTTPStatus
Follow-up on [1]:
We don't need an HTTP client for this, we only
need status codes. Just load that instead.

[1] https://review.opendev.org/762308

Change-Id: Ib24be88c9f33889d5ed705537b0d4c167cad5b3f
2021-04-21 17:41:28 +00:00
jacky06 c3bb939e28 [Part1]Remove six
We don't need this in a Python 3-only world.

1. this PS just from six from unit test

Change-Id: Ibe08ffa9072f1f0c1090f2b9e2ab9af59474d6b1
2020-08-30 09:03:07 +00:00
Shilpa 895899f11b Check if host belongs to a segment
If you query a host passing an existing failover segment but not
the one that is assigned to the host, it still returns the host
successfully. In this case, it should fail with 404 error.

This patch checks if the host belongs to the segment that is
present in the URI. If not, it will return 404 error.

Change-Id: I16256cc2a01696a1d54cb9326aed17b723b87727
Closes-Bug: #1854323
2020-05-20 11:25:35 +05:30
Andreas Jaeger 9350d8fb83 Update hacking for Python3
The repo is Python 3 now, so update hacking to version 3.0 which
supports Python 3.

Fix problems found by updated hacking version.

Update local hacking checks to work with current flake8.

Remove hacking and friends from lower-constraints, they are not needed
there.

Change-Id: I89695a03791c2de36ab015b3831c85887b27f3b8
2020-04-19 07:41:06 +02:00
Sean McGinnis 9a59610643
Use unittest.mock instead of third party mock
Now that we no longer support py27, we can use the standard library
unittest.mock module instead of the third party mock lib.

Change-Id: Ia6927351f591be0c57fd73515b2542a0af35f82b
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
2020-04-18 11:54:10 -05:00
shilpa.devharakar d7592cbe25 Register and Document policy in code
Adds below things for the implementation of framework for registering and
using default policy rules.
* Policy-in-code
  The framework for registering and using default policy rules.
  Rules should be defined and returned from a module in
  masakari/policies/, and then added to the list in masakari/policies/__init__.py.
  A new context.can() method has been added for policy enforcement of
  registered rules. It has the same parameters as the enforce() method
  currently being used.
* Add policy sample generation
  The entry point and config file necessary for using the
  oslo.policy sample generation script. It also adds a tox target to
  simplify the usage of it.
* Add policy documentation and sample file
  Documentation and sample file for default policy in code feature.
* Hacking check for policy registration
  It ensures that policy registration happens in the centralized
  masakari/policies/ directory.
* Hacking check for _ENFORCER.enforce()
  Hacking check in order to ensure that only registered policies
  are used for authorization checks _ENFORCER.authorize should be used rather
  than _ENFORCER.enforce.
* Add entry_point for oslo policy scripts
  There are two helper scripts in oslo.policy to help deployers understand
  their policy configuration better. With the setup.cfg entry these can be
  called directly from oslo.policy.

Changes done here are with the reference of [1] at NOVA side
which is contributed by Andrew Laski and Claudiu Belu

[1] https://review.openstack.org/#/q/topic:bp/policy-in-code+project:openstack/nova+status:merged

Change-Id: If885a66d92c31be440d27d6780635800a0b12e3e
2018-07-27 12:15:14 +05:30
Dinesh Bhor a1bbcd4d98 Fix 'host delete' delete's host of another segment
Currently masakari delete's the host which doesn't belong to the
segment requested in the 'host delete' API's request URL because
host was not getting filtered on the basis of failover_segment_id.

Filtered the host based on 'failover_segment_id'. Added a new
exception 'HostNotFoundUnderFailoverSegment' which will be raised
from db API 'host_get_by_uuid' if the host is not found under the
requested failover_segment. This exception is not caught at API
controller layer as it is a subclass of 'HostNotFound' which is
already caught in controller.

Closes-Bug: #1697629
Change-Id: I3d3e8cffa2f8ea443ccd13b1db61fda55bc07a0d
2017-08-01 12:28:56 +05:30
Dinesh Bhor d4f982449e Use os-testr instead of testr
Masakari should use ostestr instead of testr. ostestr is more
powerful and provide much prettier output than testr. Other
projects like cinder, nova, glance, neutron etc already uses
the ostestr wrapper.

Using ostestr shows each tests execution separately because of
which it has shown errors related to "KeyError" in existing test
cases. The error looks like below:

"Exception in string format operation: KeyError: u'id'"

This happens if we don't pass keyword argument like "id" to
exception which we expect to be raised from test through
side_effect [1]. This doesn't lead to test failure but it
appears in test logs. This patch fixes such issues by passing
expected keyword arguments to exceptions.

[1] https://github.com/openstack/masakari/blob/master/masakari/tests/unit/api/openstack/ha/test_hosts.py#L364
Change-Id: I91603ea3dcf35fd20a00dcf477b93d612edca362
2017-07-05 17:37:52 +05:30
hussainchachuliya 72e6d5596b Use DDT to reduce test code duplication
DDT can ease up error tracing and auto generates tests on
basis of different input data.
Reduce test code data by using DDT for segments, hosts, and
notifications.

Co-author: Dinesh Bhor <dinesh.bhor@nttdata.com>
Change-Id: Ie3ce3316c6e2fc3f98df3a51db59ca7f1f1625b8
2017-04-19 16:27:44 +05:30
poojajadhav c2bf0d8b57 Boolean filters are not working for host list api
If user tries to retrieve hosts along with filter set for on_maintenance
or reserved as True, it always returns records with boolean filters set
to False, irrespective of the value provided to boolean filters flag in
the filter.

This patch fixes boolean filter issue by converting value from string to
boolean using oslo_utils.strutils method.

Closes-Bug: #1658911
Change-Id: I5eed5c75f2b7613196dcf1686e5dd983f31c2a81
2017-02-14 12:44:05 +05:30
Dinesh Bhor 4f4c42bd8d Extracted HTTP response codes to constants
There are several places in the source code where HTTP response
codes are used as numeric values.

All of the used status codes are replaced with symbolic constants
from six.moves.http_client to improve code readibility.

Closes-Bug: #1520159

Change-Id: Ic5e439fb1f33962979536fe1ac5e5320e2c50c40
2017-01-10 12:25:41 +05:30
hussainchachuliya 5e6e0c49be Add database related test cases
Added unit tests for migration scripts and host, failover_segment
and notification db api's.

Change-Id: Ifa0a421d0a708d90bf25726803a38cb432466fab
2016-12-09 18:30:55 +05:30
dineshbhor de2d40be74 Return correct response codes
Following apis are returning incorrect response codes but according
to api-guidelines [1] they should return following responses:

    POST: notification create:
          old_response: 200, new_response: 202
    DELETE: notification delete:
          old_response: 404, new_response: 405
    PUT: notification update:
          old_response: 404, new_response: 405
    POST: Host create:
          old_response: 200, new_response: 201
    DELETE: Host delete:
          old_response: 200, new_response: 204
    POST: Failover-segment create:
          old_response: 200, new_response: 201
    DELETE: Failover-segment delete:
          old_response: 200, new_response: 204

[1] https://specs.openstack.org/openstack/api-wg/guidelines/http.html#failure-code-clarifications

APIImpact
Closes-Bug: #1645699
Change-Id: Ia4569d61bdebba9f8778dd1c09a8334d5b76096b
2016-11-30 15:29:36 +05:30
hussainchachuliya 030c8e3b6f Fix 500 error while create/update host
Creating or updating a host with 'type' more than 255 characters
returns 500 error.

This patch fixes the issue by validing the 'type' length upto
255 characters in the schema itself.

Closes-bug: #1640156

Change-Id: I8978a0bae3d6832f2216f56f0303dc3d3996db46
2016-11-08 12:39:48 +00:00
dineshbhor 77dd1ea0bd Fix 500 if you pass invalid sort_key and sort_dir
Host and failover segments list apis return 500 InternalServerError if
you pass invalid sort_key or sort_dir.

Caught exception.InvalidSortKey at controller level and also allowed
multiple sort_keys and sort_dirs to pass.

NOTE:
Allowed to pass multiple sort keys to list apis.
Also moved the processing of request parameters from masakari/ha/api.py
to respective failover segments and hosts controllers as request parameters
should be handled in controller itself.

Closes-Bug: #1630530
Change-Id: Ib9d0faf5ca737a020099d5bac2b2ca0b03aa353e
2016-10-06 14:42:17 +05:30
dineshbhor 2e267e6604 Added host controller for masakari
Host controller will allow user to do CRUD operations on hosts.
Added authorize policy for host controller methods as these are
going to be called by admin only.

Change-Id: I9871d4163d13bddfa49e6ee5f532de641711c30e
2016-09-23 13:56:19 +05:30