Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compute v2: Availability Zones Info #704

Merged
merged 9 commits into from
Jan 8, 2018

Conversation

dstdfx
Copy link
Contributor

@dstdfx dstdfx commented Jan 3, 2018

Add ability to get list and detailed AZs info

For #320

Links to the line numbers/files in the OpenStack source code that support the
code in this PR:

Add ability to get list and detailed AZs info
@coveralls
Copy link

coveralls commented Jan 3, 2018

Coverage Status

Coverage increased (+0.1%) to 72.953% when pulling a3e8e09 on dstdfx:availability-zones-info into 2f0d338 on gophercloud:master.

Copy link
Contributor

@jtopjian jtopjian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dstdfx Thank you for working on this. I did a cursory review and spotted a few things that need changed.

First, can you use the following test fixture?

{
    "availabilityZoneInfo": [
        {
            "hosts": {
                "localhost": {
                    "nova-cert": {
                        "active": true,
                        "available": false,
                        "updated_at": "2017-10-14T17:03:39.000000"
                    },
                    "nova-conductor": {
                        "active": true,
                        "available": false,
                        "updated_at": "2017-10-14T17:04:09.000000"
                    },
                    "nova-consoleauth": {
                        "active": true,
                        "available": false,
                        "updated_at": "2017-10-14T17:04:18.000000"
                    },
                    "nova-scheduler": {
                        "active": true,
                        "available": false,
                        "updated_at": "2017-10-14T17:04:30.000000"
                    }
                },
                "openstack-acc-tests.novalocal": {
                    "nova-cert": {
                        "active": true,
                        "available": true,
                        "updated_at": "2018-01-04T04:11:19.000000"
                    },
                    "nova-conductor": {
                        "active": true,
                        "available": true,
                        "updated_at": "2018-01-04T04:11:22.000000"
                    },
                    "nova-consoleauth": {
                        "active": true,
                        "available": true,
                        "updated_at": "2018-01-04T04:11:20.000000"
                    },
                    "nova-scheduler": {
                        "active": true,
                        "available": true,
                        "updated_at": "2018-01-04T04:11:23.000000"
                    }
                }
            },
            "zoneName": "internal",
            "zoneState": {
                "available": true
            }
        },
        {
            "hosts": {
                "openstack-acc-tests.novalocal": {
                    "nova-compute": {
                        "active": true,
                        "available": true,
                        "updated_at": "2018-01-04T04:11:23.000000"
                    }
                }
            },
            "zoneName": "nova",
            "zoneState": {
                "available": true
            }
        }
    ]
}

If I recall correctly, the blocker I spotted in #327 was that the test fixture was incorrect. The above fixture is pulled from a running openstack environment so we can guarantee it works.

Second, OS should be removed from the names/variables. ie instead of OSAvailabilityZonePage, it should be AvailabilityZonePage.

I haven't done an exhaustive review of this yet, but the above items should be fixed before any further review is done.

Again, thank you for working on this and let me know if you have any questions.

// UnmarshalJSON to override default
func (r *ServerAvailabilityZoneExt) UnmarshalJSON(b []byte) error {
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was removed sometime after #327 was opened. Can you remove this function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for feedback!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jtopjian is it okay to leave ComputeAvailabilityZonePage name instead OSAvailabilityZonePage ? The problem is that we've already used AvailabilityZonePage name in openstack/sharedfilesystems/v2/availabilityzones/results.go.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can re-use the name AvailabilityZonePage. The other AvailabilityZonePage is in another Go package and, unless I'm mistaken, there won't be a name collision.

@coveralls
Copy link

coveralls commented Jan 4, 2018

Coverage Status

Coverage increased (+0.06%) to 72.878% when pulling 15ebf51 on dstdfx:availability-zones-info into f05feab on gophercloud:master.

* Change `AvailabilityZoneInfo` type from `struct` to `slice`
* Add custom `UnmarshalJSON` to `AvailabilityZoneInfo`
* Get rid of 'OS' prefixes in variable's names
@coveralls
Copy link

coveralls commented Jan 4, 2018

Coverage Status

Coverage increased (+0.07%) to 72.885% when pulling d7a80ae on dstdfx:availability-zones-info into f05feab on gophercloud:master.

Copy link
Contributor

@jtopjian jtopjian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dstdfx This is looking good - nice work.

I did a more detailed review and left some comments. Please let me know if you have any questions.

Additionally, would you be able to provide an acceptance test for this? The file would be contained under acceptance/openstack/compute/v2.

More information about acceptance tests can be found here: https://github.com/gophercloud/gophercloud/tree/master/acceptance


type ServerWithAZ struct {
servers.Server
availabilityzones.ServerAvailabilityZoneExt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example should not be removed.


allPages, err := servers.List(client, nil).AllPages()
allPages, err := az.ListDetail(computeClient).AllPages()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

az is not a valid package name.

fmt.Println(hostname)
// to be continued ...
// cut for brevity :)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following should work here:

for _, zoneInfo := range availabilityZoneInfo {
  fmt.Printf("%+v\n", zoneInfo)
}

type ServerAvailabilityZoneExt struct {
// AvailabilityZone is the availabilty zone the server is in.
AvailabilityZone string `json:"OS-EXT-AZ:availability_zone"`
}

type StateofService struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's change this to ServiceState.

NovaScheduler StateofService `json:"nova-scheduler"`
NovaCompute StateofService `json:"nova-compute"`
NovaCert StateofService `json:"nova-cert"`
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above is hard-coding each of the nova services into Gophercloud. By doing this, each Host result will contain all of the above services even if they are not part of the availability zone. For example, this is the result of running this code in my test environment:

                  "hosts": {
                    "openstack-acc-tests.novalocal": {
                      "nova-conductor": {
                        "active": false,
                        "available": false,
                        "updated_at": "0001-01-01T00:00:00Z"
                      },
                      "nova-consoleauth": {
                        "active": false,
                        "available": false,
                        "updated_at": "0001-01-01T00:00:00Z"
                      },
                      "nova-network": {
                        "active": false,
                        "available": false,
                        "updated_at": "0001-01-01T00:00:00Z"
                      },
                      "nova-scheduler": {
                        "active": false,
                        "available": false,
                        "updated_at": "0001-01-01T00:00:00Z"
                      },
                      "nova-compute": {
                        "active": true,
                        "available": true,
                        "updated_at": "2018-01-05T03:16:04Z"
                      },
                      "nova-cert": {
                        "active": false,
                        "available": false,
                        "updated_at": "0001-01-01T00:00:00Z"
                      }
                    }
                  },
                  "zoneName": "nova",
                  "zoneState": {
                    "available": true
                  }
                }

Instead of doing the above, I think we should do:

type Service map[string]ServiceState

When I modify this PR to be the above, I now see this:

                  "hosts": {
                    "openstack-acc-tests.novalocal": {
                      "nova-compute": {
                        "active": true,
                        "available": true,
                        "updated_at": "2018-01-05T03:26:34Z"
                      }
                    }
                  },
                  "zoneName": "nova",
                  "zoneState": {
                    "available": true
                  }
                }

Which I think is more accurate.

Please let me know if I am incorrect about this.

// AvailabilityZone contains all the information associated with an OpenStack
// AvailabilityZone.
type AvailabilityZone struct {
Hosts `json:"hosts"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hosts Hosts `json:"hosts"`

Hosts `json:"hosts"`
// The availability zone name
ZoneName string `json:"zoneName"`
ZoneState `json:"zoneState"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ZoneState ZoneState `json:"zoneState"`

}

// AvailabilityZoneInfo contains list of AvailabilityZone info
type AvailabilityZoneInfo []AvailabilityZone
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type isn't needed.

func ExtractAvailabilityZones(r pagination.Page) (AvailabilityZoneInfo, error) {
var a AvailabilityZoneInfo
err := (r.(AvailabilityZonePage)).ExtractInto(&a)
return a, err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of the above, use:

var s struct {
  AvailabilityZoneInfo []AvailabilityZone `json:"availabilityZoneInfo`
}
err := (r.(AvailabilityZonePage)).ExtractInto(&s)
return s.AvailabilityZoneInfo, err               

* Rename `ServiceOfState` to `ServiceState`
* Change type `Services` from `struct` to `map[string]ServiceState`
* Delete useless type `AvailabilityZoneInfo`
* Update doc.go
@coveralls
Copy link

coveralls commented Jan 5, 2018

Coverage Status

Coverage increased (+0.08%) to 72.901% when pulling a4be04e on dstdfx:availability-zones-info into f05feab on gophercloud:master.

Copy link
Contributor

@jtopjian jtopjian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dstdfx Just one more change. I apologize that I didn't catch this yesterday.

Once this change is made, this PR is good to go. Thank you very much for your work on it. 😄

type ServiceState struct {
Active bool `json:"active"`
Available bool `json:"available"`
UpdatedAt time.Time `json:"updated_at"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UpdatedAt time.Time `json:"-"`

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, useless struct tag!

@coveralls
Copy link

coveralls commented Jan 6, 2018

Coverage Status

Coverage increased (+0.08%) to 72.901% when pulling e122ead on dstdfx:availability-zones-info into f05feab on gophercloud:master.

@jtopjian
Copy link
Contributor

jtopjian commented Jan 8, 2018

@dstdfx This looks good to me. I've also verified it on a new Pike environment and everything is parsing correctly.

Nice work!

@jtopjian jtopjian merged commit b2bf8a6 into gophercloud:master Jan 8, 2018
@dstdfx dstdfx deleted the availability-zones-info branch January 8, 2018 10:05
@dstdfx dstdfx changed the title Compute availability zones info support Compute v2: Availability Zones Info Support Jan 17, 2018
@dstdfx dstdfx changed the title Compute v2: Availability Zones Info Support Compute v2: Availability Zones Info support Jan 17, 2018
@dstdfx dstdfx changed the title Compute v2: Availability Zones Info support Compute v2: Availability Zones Info Jan 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants