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

Synergy support option 2 #99

Merged
merged 14 commits into from
Jan 12, 2017
Merged

Synergy support option 2 #99

merged 14 commits into from
Jan 12, 2017

Conversation

jsmartt
Copy link
Contributor

@jsmartt jsmartt commented Jan 10, 2017

Description

This PR offers another option for addressing support for Synergy and future OV releases. (At this point I just have the ethernet_network providers done.) The logic for resources is split up into separate providers for each API version and variant. Here are the basic features:

  • Run-time loading of the correct SDK module, variant, and class.
  • Can use multiple SDK variants & API versions in a single Chef run
  • Can override the X-API-Version header in API requests by setting a property on a resource
  • Basically all the logic is split out into Provider classes, not modules
  • Provider classes expose many of the helper methods have been copied into the provider class so they can be easily used where they will be needed

Compared to #96, this option will require more work to refactor, but I think it's worth it.

Issues Resolved

Fixes #97

Check List

  • New functionality includes testing.
  • New functionality has been documented in the README if applicable.
    • New functionality has been thoroughly documented in examples (please include helpful comments).
  • Changes documented in the CHANGELOG.

@tmiotto or others, let me know what you think!

module OneviewCookbook
module API200
# Base class for API200 resource providers
class EthernetNetwork < OneviewCookbook::ResourceProvider
Copy link
Contributor

Choose a reason for hiding this comment

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

EthernetNetwork? I don't get it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops. Should be fixed now.

module OneviewCookbook
module API200
# Base class for API200 resource providers
class ResourceProvider < OneviewCookbook::ResourceProvider
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, but why do we have this?

It is to add any shared behavior specific to API200? If so, shouldn't we have to do something similar to API300 or C7000 and Synergy?

Copy link
Contributor Author

@jsmartt jsmartt Jan 10, 2017

Choose a reason for hiding this comment

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

Yes. I didn't include the one for API300 and the variants YET, but yes, the concept is the same. We'd add the default class in there. Exactly like the Resource class for the SDK

@@ -0,0 +1,4 @@
~FC011
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 foodcritic is failing because we're running it from the wrong directory.

Actually, it should receive as parameter the cookbooks/ folder, so it gets our oneview cookbook and then analyzes it. But in this case it is being executed inside oneview/, so this way it is interpreting the libraries as a separate cookbook, and not a subfolder

Copy link
Contributor

@tmiotto tmiotto Jan 10, 2017

Choose a reason for hiding this comment

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

Well, it's not exactly the wrong directory, but running on cookbooks/ would solve the problem (but this is a workaround), or maybe we should just add an exclude_path if we don't want libraries to be analyzed by it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can't get it to not see the libraries directory as a separate cookbook, which is why I put that .foodcritic file in there. How are you able to run it so it gets ignored?

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 travis test doesn't have a cookbooks directory. Just this repo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the real issue is that foodcritic thinks the libraries directory is a cookbook because of the resources directory within it. We can rename the directory to avoid these issues. See this issue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be fixed now

@tmiotto
Copy link
Contributor

tmiotto commented Jan 10, 2017

These changes from the PR #96 should be added to stop the spec from failing.

@jsmartt
Copy link
Contributor Author

jsmartt commented Jan 11, 2017

Added some more tests and functionality. I think the functionality for EthernetNetworkProvider is now done. Just need a few more test, but I'll get to those tomorrow.

@@ -20,7 +20,7 @@ module API300
# @return [Class] Resource class or nil if not found
def self.resource_named(type, variant)
raise "API300 variant #{variant} is not supported!" unless SUPPORTED_VARIANTS.include?(variant.to_s)
new_type = type.to_s.downcase.gsub(/[ -_]/, '')
new_type = type.to_s.downcase.gsub(/[ -_]/, '') + 'provider'
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we still be calling it resource_named?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you suggest instead? resource_provider_named ?

Copy link
Contributor

Choose a reason for hiding this comment

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

It is an option, or maybe just provider_named.

@@ -27,3 +27,14 @@
expect(real_chef_run).to create_oneview_ethernet_network('EthernetNetwork1')
end
end

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we would not want to implement tests of things that are already being tested on API200

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. This is just a sample of what you would do if you wanted to test API300 resources. I think this particular one is probably OK to leave in since it's the only one so far, but we wouldn't have to add these sort of tests for other resources that are the same as API200.

@tmiotto
Copy link
Contributor

tmiotto commented Jan 11, 2017

@jsmartt Just one more thought...

As far as we go through the implementation, we'll always be using the last API version as base for the next one, i.e. API300::X < API200::X, API500::X < API300::X.

Said that we won't be using any ResourceProvider other than the OneviewCookbook::ResourceProvider since API500::X < API300::X < API200::X < OneviewCookbook::ResourceProvider, and the ones created aren't adding anything new.

It won't be better to just have the OneviewCookbook::ResourceProvider?

@jsmartt
Copy link
Contributor Author

jsmartt commented Jan 11, 2017

Yeah, I guess I added the API200 sub-class prematurely. We don't need it now, so there's no need to include it. I'll remove it

@jsmartt
Copy link
Contributor Author

jsmartt commented Jan 11, 2017

OK @tmiotto , I'm ready on this when you are 😄

@tmiotto tmiotto merged commit 7e0f5bd into master Jan 12, 2017
@jsmartt jsmartt deleted the synergy_jared branch January 12, 2017 15:07
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.

2 participants