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

Add openstacksdk option to openstack_controller #3109

Merged
merged 23 commits into from
Feb 18, 2019

Conversation

coignetp
Copy link
Contributor

What does this PR do?

Add the OpenstackSdkApi option to the api factory of openstack_controller. It uses openstacksdk (v 0.24.0)

Motivation

Review checklist

  • PR has a meaningful title or PR has the no-changelog label attached
  • Feature or bugfix has tests
  • Git history is clean
  • If PR impacts documentation, docs team has been notified or an issue has been opened on the documentation repo
  • If PR adds a configuration option, it has been added to the configuration file.

Additional Notes

Openstacksdk is in version 0.24.0 and is not complete yet.

  • hypervisor_uptime is not available with openstacksdk yet, so the metrics hypervisor_load.1, hypervisor_load.5 and hypervisor_load.15 can't be created (this is like setting collect_hypervisor_load to False in the configuration file).
  • server_diagnostics is not available with openstacksdk yet, but it should be available in the next release (commit), so a few metrics are not created (this is like setting collect_server_diagnostic_metrics to False).

@coignetp coignetp requested review from a team as code owners February 13, 2019 16:56
@codecov
Copy link

codecov bot commented Feb 13, 2019

Codecov Report

Merging #3109 into master will decrease coverage by 4.58%.
The diff coverage is 90.73%.

@@            Coverage Diff             @@
##           master    #3109      +/-   ##
==========================================
- Coverage   84.51%   79.92%   -4.59%     
==========================================
  Files         675       68     -607     
  Lines       36297     5894   -30403     
  Branches     4307      642    -3665     
==========================================
- Hits        30675     4711   -25964     
+ Misses       4362     1020    -3342     
+ Partials     1260      163    -1097

Copy link
Contributor

@gzussa gzussa left a comment

Choose a reason for hiding this comment

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

This is great 💯 🥇 . Definitely on the right track 👏 . I made a few comments to push this the extra mile.

# - <KEY_2>:<VALUE_2>

## @param openstack_sdk_config_file_path - optional - string
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 move these up in the config next to user. Also let's explain how user can authenticate using one or the other.

## Absolute path of the configuration file for the connection to openstack with openstacksdk.
#
# openstack_sdk_config_file_path: "/path/to/file.yaml"
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 remove sdk

## Name of the cloud configuration to use
#
# openstack_sdk_cloud_name: "simple-cloud"
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 remove sdk. In general, the config should not expose how thing are being done under the hood. This is not a strong rule 😄

@@ -1 +1,2 @@
datadog-checks-dev
openstacksdk==0.24.0
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 remove this since it's is not in addition to regular deps

@@ -700,7 +708,8 @@ def check(self, instance):
self.collect_hypervisors_metrics(custom_tags=custom_tags,
use_shortname=use_shortname,
collect_hypervisor_metrics=collect_hypervisor_metrics,
collect_hypervisor_load=collect_hypervisor_load)
collect_hypervisor_load=collect_hypervisor_load,
openstack_sdk_cloud_name=openstack_sdk_cloud_name)
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to have this within the api implementation and have the api function that is not supported raise an exception that we would then catch in the check?

@@ -72,6 +83,158 @@ def get_networks(self):
raise NotImplementedError()


class OpenstackSdkApi(AbstractApi):
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we rename this OpenstackSDKApi. Not a big deal tho, completely opinionated and definitely coming from my OCD issues 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

Says the one who wrote Api :trollface:


api = None

if openstack_sdk_cloud_name is None:
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 add comments here to explain what is going on for people you don't have the full context.

@@ -1,6 +1,8 @@
# (C) Datadog, Inc. 2018
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
from openstack import connection
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 move from .... import ... after import ...

api = OpenstackSdkApi(None)
api.connection = MockOpenstackConnection()

assert api.get_os_hypervisors_detail() == EXAMPLE_HYPERVISORS_VALUE
Copy link
Contributor

Choose a reason for hiding this comment

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

For all these methods, is the output the same as what the simpleApi Would return.
It would be great to use the same assertion values in both cases just to make sure things match.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some of these methods return more information than SimpleApi, and some less information (not used by the check). There are some commentary for the methods that have less information.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess the tests then should only assert for values actually used by the check, then we can keep the same assertions for both APIs

MissingNovaEndpoint, MissingNeutronEndpoint)


EXAMPLE_PROJECTS_VALUE = [
Copy link
Contributor

Choose a reason for hiding this comment

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

For all these Api output, do you have a link to the doc that can help check out the structure?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The doc does not specify the output, I called each methods from the test env to have their explicit output.

Copy link
Contributor

@zippolyte zippolyte left a comment

Choose a reason for hiding this comment

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

Awesome 👍, small nits aside :)

@coignetp coignetp requested review from a team as code owners February 15, 2019 09:46
@coignetp coignetp force-pushed the paul/openstack-controller-sdk branch from 7f19bff to 1aba6f4 Compare February 15, 2019 09:54
## @param openstack_config_file_path - optional - string
## Absolute path of the configuration file for the connection to openstack with openstacksdk.
#
# openstack_config_file_path: "/path/to/file.yaml"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# openstack_config_file_path: "/path/to/file.yaml"
# openstack_config_file_path: <PATH_TO_YAML_FILE>

Copy link
Contributor

Choose a reason for hiding this comment

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

## openstack_config_file_path, or at the default location:
## ~/.config/openstack or /etc/openstack
#
# openstack_cloud_name: "simple-cloud"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# openstack_cloud_name: "simple-cloud"
# openstack_cloud_name: <CLOUD_NAME>

gzussa
gzussa previously approved these changes Feb 18, 2019
Copy link
Contributor

@gzussa gzussa left a comment

Choose a reason for hiding this comment

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

Looks good to me. Great Job!

arbll
arbll previously approved these changes Feb 18, 2019
Copy link
Member

@arbll arbll left a comment

Choose a reason for hiding this comment

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

🐍

@l0k0ms l0k0ms dismissed stale reviews from arbll and gzussa via c683c98 February 18, 2019 13:13
Copy link
Contributor

@l0k0ms l0k0ms left a comment

Choose a reason for hiding this comment

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

Fixed some issue in the configuration file, otherwise LGTM 👌

@gzussa gzussa merged commit 97b0144 into master Feb 18, 2019
@ofek ofek deleted the paul/openstack-controller-sdk branch February 18, 2019 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants