Skip to content

Commit

Permalink
Stop using "nova" in API samples when creating a server
Browse files Browse the repository at this point in the history
The "availability_zone" parameter for server create in the
API reference and the availabilty zone user docs both say
that users should not use the default availability zone (nova)
yet our server create API samples use "nova" which is...bad.

This change fixes the API samples and related tests to use
a fake "us-west" availability zone. For any samples that were
requesting an AZ when creating a server, those are changed from
requesting "nova" to requesting "us-west" and a new
AvailabilityZoneFixture is added to stub out the code used to
validate the requested AZ and what is shown in server detail
responses.

Some unused samples are removed from the os-availability-zone
directory and the API reference and AZ user docs are updated for
formatting and linking to other docs for reference.

Change-Id: I3161157f15f05a3ffaaf1b48e7beb6b3e59c5513
Closes-Bug: #1817963
  • Loading branch information
mriedem committed Mar 1, 2019
1 parent 68d4cb4 commit 1241e3e
Show file tree
Hide file tree
Showing 65 changed files with 137 additions and 138 deletions.
2 changes: 2 additions & 0 deletions api-ref/source/os-availability-zone.inc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.. -*- rst -*-
.. _os-availability-zone:

===========================================
Availability zones (os-availability-zone)
===========================================
Expand Down
13 changes: 8 additions & 5 deletions api-ref/source/parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4842,18 +4842,21 @@ os-availability-zone:availability_zone:
want your instance to be built. Typically, an admin user will use
availability zones to arrange OpenStack compute hosts into logical
groups.
An availability zone provides a form of physical isolation and redundancy from
other availability zones. For instance, if some racks in your data center are
on a separate power source, you can put servers in those racks in their own availability
zone. Availability zones can also help separate different classes of hardware. By
segregating resources into availability zones, you can ensure that your application
resources are spread across disparate machines to achieve high availability in
the event of hardware or other failure.
the event of hardware or other failure. See
`Availability Zones (AZs) <https://docs.openstack.org/nova/latest/user/aggregates.html#availability-zones-azs>`_ for more information.
You can list the available availability zones by calling the
os-availability-zone API, but you should avoid using the default
availability zone when booting the instance. In general, the
default availability zone is named ``nova``. This AZ is only shown
when listing the availability zones as an admin.
:ref:`os-availability-zone` API, but you should avoid using the `default
availability zone <https://docs.openstack.org/nova/latest/configuration/config.html#DEFAULT.default_availability_zone>`_
when creating the server. The default availability zone is named ``nova``.
This AZ is only shown when listing the availability zones as an admin.
in: body
required: false
type: string
Expand Down

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion doc/api_samples/os-rescue/server-get-resp-rescue.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"user_id": "fake",
"config_drive": "",
"OS-DCF:diskConfig": "AUTO",
"OS-EXT-AZ:availability_zone": "nova",
"OS-EXT-AZ:availability_zone": "us-west",
"OS-EXT-SRV-ATTR:host": "b8b357f7100d4391828f2177c922ef93",
"OS-EXT-SRV-ATTR:hypervisor_hostname": "fake-mini",
"OS-EXT-SRV-ATTR:instance_name": "instance-00000001",
Expand Down
2 changes: 1 addition & 1 deletion doc/api_samples/os-rescue/server-get-resp-unrescue.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"user_id": "fake",
"config_drive": "",
"OS-DCF:diskConfig": "AUTO",
"OS-EXT-AZ:availability_zone": "nova",
"OS-EXT-AZ:availability_zone": "us-west",
"OS-EXT-SRV-ATTR:host": "b8b357f7100d4391828f2177c922ef93",
"OS-EXT-SRV-ATTR:hypervisor_hostname": "fake-mini",
"OS-EXT-SRV-ATTR:instance_name": "instance-00000001",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"description": null,
"config_drive": "",
"OS-DCF:diskConfig": "AUTO",
"OS-EXT-AZ:availability_zone": "nova",
"OS-EXT-AZ:availability_zone": "us-west",
"OS-EXT-SRV-ATTR:host": "b8b357f7100d4391828f2177c922ef93",
"OS-EXT-SRV-ATTR:hypervisor_hostname": "fake-mini",
"OS-EXT-SRV-ATTR:instance_name": "instance-00000001",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"description": null,
"config_drive": "",
"OS-DCF:diskConfig": "AUTO",
"OS-EXT-AZ:availability_zone": "nova",
"OS-EXT-AZ:availability_zone": "us-west",
"OS-EXT-SRV-ATTR:host": "c3f14e9812ad496baf92ccfb3c61e15f",
"OS-EXT-SRV-ATTR:hypervisor_hostname": "fake-mini",
"OS-EXT-SRV-ATTR:instance_name": "instance-00000001",
Expand Down
2 changes: 1 addition & 1 deletion doc/api_samples/servers/server-create-req-v237.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name" : "new-server-test",
"imageRef" : "70a599e0-31e7-49b7-b260-868f441e862b",
"flavorRef" : "1",
"availability_zone": "nova",
"availability_zone": "us-west",
"OS-DCF:diskConfig": "AUTO",
"metadata" : {
"My Server Name" : "Apache1"
Expand Down
2 changes: 1 addition & 1 deletion doc/api_samples/servers/server-create-req-v257.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name" : "new-server-test",
"imageRef" : "70a599e0-31e7-49b7-b260-868f441e862b",
"flavorRef" : "http://openstack.example.com/flavors/1",
"availability_zone": "nova",
"availability_zone": "us-west",
"OS-DCF:diskConfig": "AUTO",
"metadata" : {
"My Server Name" : "Apache1"
Expand Down
2 changes: 1 addition & 1 deletion doc/api_samples/servers/server-create-req.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name" : "new-server-test",
"imageRef" : "70a599e0-31e7-49b7-b260-868f441e862b",
"flavorRef" : "1",
"availability_zone": "nova",
"availability_zone": "us-west",
"OS-DCF:diskConfig": "AUTO",
"metadata" : {
"My Server Name" : "Apache1"
Expand Down
2 changes: 1 addition & 1 deletion doc/api_samples/servers/server-get-resp.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"name": "new-server-test",
"config_drive": "",
"OS-DCF:diskConfig": "AUTO",
"OS-EXT-AZ:availability_zone": "nova",
"OS-EXT-AZ:availability_zone": "us-west",
"OS-EXT-SRV-ATTR:host": "b8b357f7100d4391828f2177c922ef93",
"OS-EXT-SRV-ATTR:hypervisor_hostname": "fake-mini",
"OS-EXT-SRV-ATTR:instance_name": "instance-00000001",
Expand Down
2 changes: 1 addition & 1 deletion doc/api_samples/servers/servers-details-resp.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"name": "new-server-test",
"config_drive": "",
"OS-DCF:diskConfig": "AUTO",
"OS-EXT-AZ:availability_zone": "nova",
"OS-EXT-AZ:availability_zone": "us-west",
"OS-EXT-SRV-ATTR:host": "c3f14e9812ad496baf92ccfb3c61e15f",
"OS-EXT-SRV-ATTR:hypervisor_hostname": "fake-mini",
"OS-EXT-SRV-ATTR:instance_name": "instance-00000001",
Expand Down
2 changes: 1 addition & 1 deletion doc/api_samples/servers/v2.16/server-get-resp.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"name": "new-server-test",
"config_drive": "",
"OS-DCF:diskConfig": "AUTO",
"OS-EXT-AZ:availability_zone": "nova",
"OS-EXT-AZ:availability_zone": "us-west",
"OS-EXT-SRV-ATTR:host": "c5f474bf81474f9dbbc404d5b2e4e9b3",
"OS-EXT-SRV-ATTR:hypervisor_hostname": "fake-mini",
"OS-EXT-SRV-ATTR:instance_name": "instance-00000001",
Expand Down
2 changes: 1 addition & 1 deletion doc/api_samples/servers/v2.16/servers-details-resp.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"name": "new-server-test",
"config_drive": "",
"OS-DCF:diskConfig": "AUTO",
"OS-EXT-AZ:availability_zone": "nova",
"OS-EXT-AZ:availability_zone": "us-west",
"OS-EXT-SRV-ATTR:host": "bc8efe4fdb7148a4bb921a2b03d17de6",
"OS-EXT-SRV-ATTR:hypervisor_hostname": "fake-mini",
"OS-EXT-SRV-ATTR:instance_name": "instance-00000001",
Expand Down
2 changes: 1 addition & 1 deletion doc/api_samples/servers/v2.3/server-get-resp.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"name": "new-server-test",
"config_drive": "",
"OS-DCF:diskConfig": "AUTO",
"OS-EXT-AZ:availability_zone": "nova",
"OS-EXT-AZ:availability_zone": "us-west",
"OS-EXT-SRV-ATTR:host": "b8b357f7100d4391828f2177c922ef93",
"OS-EXT-SRV-ATTR:hypervisor_hostname": "fake-mini",
"OS-EXT-SRV-ATTR:instance_name": "instance-00000001",
Expand Down
2 changes: 1 addition & 1 deletion doc/api_samples/servers/v2.3/servers-details-resp.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"name": "new-server-test",
"config_drive": "",
"OS-DCF:diskConfig": "AUTO",
"OS-EXT-AZ:availability_zone": "nova",
"OS-EXT-AZ:availability_zone": "us-west",
"OS-EXT-SRV-ATTR:host": "c3f14e9812ad496baf92ccfb3c61e15f",
"OS-EXT-SRV-ATTR:hypervisor_hostname": "fake-mini",
"OS-EXT-SRV-ATTR:instance_name": "instance-00000001",
Expand Down
2 changes: 1 addition & 1 deletion doc/api_samples/servers/v2.47/server-create-req.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name" : "new-server-test",
"imageRef" : "70a599e0-31e7-49b7-b260-868f441e862b",
"flavorRef" : "6",
"availability_zone": "nova",
"availability_zone": "us-west",
"OS-DCF:diskConfig": "AUTO",
"metadata" : {
"My Server Name" : "Apache1"
Expand Down
2 changes: 1 addition & 1 deletion doc/api_samples/servers/v2.47/server-get-resp.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"server": {
"OS-DCF:diskConfig": "AUTO",
"OS-EXT-AZ:availability_zone": "nova",
"OS-EXT-AZ:availability_zone": "us-west",
"OS-EXT-SRV-ATTR:host": "compute",
"OS-EXT-SRV-ATTR:hostname": "new-server-test",
"OS-EXT-SRV-ATTR:hypervisor_hostname": "fake-mini",
Expand Down
2 changes: 1 addition & 1 deletion doc/api_samples/servers/v2.47/servers-details-resp.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"servers": [
{
"OS-DCF:diskConfig": "AUTO",
"OS-EXT-AZ:availability_zone": "nova",
"OS-EXT-AZ:availability_zone": "us-west",
"OS-EXT-SRV-ATTR:host": "compute",
"OS-EXT-SRV-ATTR:hostname": "new-server-test",
"OS-EXT-SRV-ATTR:hypervisor_hostname": "fake-mini",
Expand Down
2 changes: 1 addition & 1 deletion doc/api_samples/servers/v2.52/server-create-req.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name" : "new-server-test",
"imageRef" : "70a599e0-31e7-49b7-b260-868f441e862b",
"flavorRef" : "http://openstack.example.com/flavors/1",
"availability_zone": "nova",
"availability_zone": "us-west",
"OS-DCF:diskConfig": "AUTO",
"metadata" : {
"My Server Name" : "Apache1"
Expand Down
2 changes: 1 addition & 1 deletion doc/api_samples/servers/v2.52/server-get-resp.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"server": {
"OS-DCF:diskConfig": "AUTO",
"OS-EXT-AZ:availability_zone": "nova",
"OS-EXT-AZ:availability_zone": "us-west",
"OS-EXT-SRV-ATTR:host": "compute",
"OS-EXT-SRV-ATTR:hostname": "new-server-test",
"OS-EXT-SRV-ATTR:hypervisor_hostname": "fake-mini",
Expand Down
2 changes: 1 addition & 1 deletion doc/api_samples/servers/v2.52/servers-details-resp.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"servers": [
{
"OS-DCF:diskConfig": "AUTO",
"OS-EXT-AZ:availability_zone": "nova",
"OS-EXT-AZ:availability_zone": "us-west",
"OS-EXT-SRV-ATTR:host": "compute",
"OS-EXT-SRV-ATTR:hostname": "new-server-test",
"OS-EXT-SRV-ATTR:hypervisor_hostname": "fake-mini",
Expand Down
2 changes: 1 addition & 1 deletion doc/api_samples/servers/v2.57/server-create-req.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name" : "new-server-test",
"imageRef" : "70a599e0-31e7-49b7-b260-868f441e862b",
"flavorRef" : "http://openstack.example.com/flavors/1",
"availability_zone": "nova",
"availability_zone": "us-west",
"OS-DCF:diskConfig": "AUTO",
"metadata" : {
"My Server Name" : "Apache1"
Expand Down
2 changes: 1 addition & 1 deletion doc/api_samples/servers/v2.63/server-create-req.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name" : "new-server-test",
"imageRef" : "70a599e0-31e7-49b7-b260-868f441e862b",
"flavorRef" : "6",
"availability_zone": "nova",
"availability_zone": "%(availability_zone)s",
"OS-DCF:diskConfig": "AUTO",
"metadata" : {
"My Server Name" : "Apache1"
Expand Down
2 changes: 1 addition & 1 deletion doc/api_samples/servers/v2.63/server-get-resp.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"server": {
"OS-DCF:diskConfig": "AUTO",
"OS-EXT-AZ:availability_zone": "nova",
"OS-EXT-AZ:availability_zone": "us-west",
"OS-EXT-SRV-ATTR:host": "compute",
"OS-EXT-SRV-ATTR:hostname": "new-server-test",
"OS-EXT-SRV-ATTR:hypervisor_hostname": "fake-mini",
Expand Down
2 changes: 1 addition & 1 deletion doc/api_samples/servers/v2.63/servers-details-resp.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"servers": [
{
"OS-DCF:diskConfig": "AUTO",
"OS-EXT-AZ:availability_zone": "nova",
"OS-EXT-AZ:availability_zone": "us-west",
"OS-EXT-SRV-ATTR:host": "compute",
"OS-EXT-SRV-ATTR:hostname": "new-server-test",
"OS-EXT-SRV-ATTR:hypervisor_hostname": "fake-mini",
Expand Down
2 changes: 1 addition & 1 deletion doc/api_samples/servers/v2.66/server-create-req.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name" : "new-server-test",
"imageRef" : "70a599e0-31e7-49b7-b260-868f441e862b",
"flavorRef" : "6",
"availability_zone": "nova",
"availability_zone": "us-west",
"OS-DCF:diskConfig": "AUTO",
"metadata" : {
"My Server Name" : "Apache1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"servers": [
{
"OS-DCF:diskConfig": "AUTO",
"OS-EXT-AZ:availability_zone": "nova",
"OS-EXT-AZ:availability_zone": "us-west",
"OS-EXT-SRV-ATTR:host": "compute",
"OS-EXT-SRV-ATTR:hostname": "new-server-test",
"OS-EXT-SRV-ATTR:hypervisor_hostname": "fake-mini",
Expand Down
2 changes: 1 addition & 1 deletion doc/api_samples/servers/v2.9/server-get-resp.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"name": "new-server-test",
"config_drive": "",
"OS-DCF:diskConfig": "AUTO",
"OS-EXT-AZ:availability_zone": "nova",
"OS-EXT-AZ:availability_zone": "us-west",
"OS-EXT-SRV-ATTR:host": "b8b357f7100d4391828f2177c922ef93",
"OS-EXT-SRV-ATTR:hypervisor_hostname": "fake-mini",
"OS-EXT-SRV-ATTR:instance_name": "instance-00000001",
Expand Down
2 changes: 1 addition & 1 deletion doc/api_samples/servers/v2.9/servers-details-resp.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"name": "new-server-test",
"config_drive": "",
"OS-DCF:diskConfig": "AUTO",
"OS-EXT-AZ:availability_zone": "nova",
"OS-EXT-AZ:availability_zone": "us-west",
"OS-EXT-SRV-ATTR:host": "c3f14e9812ad496baf92ccfb3c61e15f",
"OS-EXT-SRV-ATTR:hypervisor_hostname": "fake-mini",
"OS-EXT-SRV-ATTR:instance_name": "instance-00000001",
Expand Down
2 changes: 1 addition & 1 deletion doc/source/user/aggregates.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ between aggregates and availability zones:
availability zone
- by default a host is part of a default availability zone even if it doesn't
belong to an aggregate (the configuration option is named
``default_availability_zone``)
:oslo.config:option:`default_availability_zone`)

.. warning:: That last rule can be very error-prone. Since the user can see the
list of availability zones, they have no way to know whether the default
Expand Down
41 changes: 41 additions & 0 deletions nova/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -2117,3 +2117,44 @@ def stub_target_cell(ctxt, cell_mapping):
'nova.context.scatter_gather_cells', stub_scatter_gather_cells))
self.useFixture(fixtures.MonkeyPatch(
'nova.context.target_cell', stub_target_cell))


class AvailabilityZoneFixture(fixtures.Fixture):
"""Fixture to stub out the nova.availability_zones module
The list of ``zones`` provided to the fixture are what get returned from
``get_availability_zones``.
``get_instance_availability_zone`` will return the availability_zone
requested when creating a server otherwise the instance.availabilty_zone
or default_availability_zone is returned.
"""
def __init__(self, zones):
self.zones = zones

def setUp(self):
super(AvailabilityZoneFixture, self).setUp()

def fake_get_availability_zones(
ctxt, get_only_available=False, with_hosts=False):
# A 2-item tuple is returned if get_only_available=False.
if not get_only_available:
return self.zones, []
return self.zones
self.useFixture(fixtures.MonkeyPatch(
'nova.availability_zones.get_availability_zones',
fake_get_availability_zones))

def fake_get_instance_availability_zone(ctxt, instance):
# If the server was created with a specific AZ, return it.
reqspec = objects.RequestSpec.get_by_instance_uuid(
ctxt, instance.uuid)
requested_az = reqspec.availability_zone
if requested_az:
return requested_az
# Otherwise return the instance.availability_zone if set else
# the default AZ.
return instance.availability_zone or CONF.default_availability_zone
self.useFixture(fixtures.MonkeyPatch(
'nova.availability_zones.get_instance_availability_zone',
fake_get_instance_availability_zone))
Loading

0 comments on commit 1241e3e

Please sign in to comment.