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

Tests run in proxied systems #1230

Merged
merged 4 commits into from
Apr 24, 2017
Merged

Tests run in proxied systems #1230

merged 4 commits into from
Apr 24, 2017

Conversation

markan
Copy link
Contributor

@markan markan commented Apr 14, 2017

NOTE: Rebase and merge after CLOUD-294/fix_solr_for_pedant (#1233) lands, as it contains and depends on it.

Passes pedant in the CI environment. (But we have some intermittent test failures on ppc64le Ubuntu 12 testers)

This PR encompasses a series of changes to allow chef-server-ctl test to operate when the main chef-server endpoint is proxied behind another name, such as the automate/chef server all in one install.

When opscode-erchef base_resource_url is set differently from the server address that nginx is listening at (as is often the case when proxying) we construct the expected values in pedant incorrectly, using the server address when we should be using base_resource_url

In some cases :host_headers isn't sufficient, and we need to be flexible on what we accept for input.

I've broken it up into a series of commits for readability. I'd especially like feedback on the approach of modifying PedantHashComparator; the alternate seems to be modifying a large number of tests to disambiguate the URI we use to access the system and the resource we expect to return. See the CLOUD-294/fix_tests_mechanical branch for a sense of what that might look like.

@markan markan force-pushed the CLOUD-294/fix_tests_imp branch 4 times, most recently from 6a11445 to 72131d9 Compare April 20, 2017 22:00
@markan
Copy link
Contributor Author

markan commented Apr 21, 2017

@chef/chef-server-maintainers

Copy link
Contributor

@sdelano sdelano left a comment

Choose a reason for hiding this comment

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

Nice work. Thanks for addressing this!

@markan markan force-pushed the CLOUD-294/fix_tests_imp branch from 72131d9 to ca48ec8 Compare April 21, 2017 23:07
markan added 2 commits April 21, 2017 16:27
In a proxied configuration Pedant needs to be aware of the different
between the place the server is listening at (platform.server) and the
resource that users actually contact. We frequently construct our
expected values based on the first, when the actual API will be
returning the second. We add a base_resource_url to the config and
platform data to enable us to distinquish that in tests.

Signed-off-by: Mark Anderson <[email protected]>
This exposes the base_resource_url in the platform config, and adds a
resource_url helper function to assist in constructing URLs.

Signed-off-by: Mark Anderson <[email protected]>
@markan markan force-pushed the CLOUD-294/fix_tests_imp branch from ca48ec8 to cedfb67 Compare April 21, 2017 23:28
Copy link
Contributor

@srenatus srenatus left a comment

Choose a reason for hiding this comment

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

Code wise, I think this change is fine.

This solves the problem by normalizing every appearance of
platform.server into platform.base_resource_url.

I'm trying to understand the use case better:
when Chef server is proxied, it will be the case that a response JSON object contains references to https://something:8443/organizations/someorg/sth, but the tests don't account for this and expect the string to be https://something/organizations/someorg/sth?

In that case, I wonder if we at all want the :8443 bit to leak out and if it wouldn't be cleaner to have erchef and friends return the "outside address" 🤔

# Our comparisons are more complex than simple value
spec.each_with_index do |newspec, x|
return false unless PedantHashComparator.new(newspec, @mode).matches? value[x]
return true if spec.all? do |s|
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] isn't this return true if ... followed by return false equivalent to ending the method with

spec.all? do ...

? 😉

Copy link
Contributor

@stevendanna stevendanna left a comment

Choose a reason for hiding this comment

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

Overall this change looks OK. I have one question (inline).

#
def normalize(candidate)
if candidate.is_a?(String)
candidate.sub(/#{Pedant::Config.pedant_platform.server}/, Pedant::Config.pedant_platform.base_resource_url)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there an advantage of coercing both the expected and configured value at the time of the comparison versus changing the code that generates the expected URL to always be correct:

https://github.com/chef/chef-server/pull/1230/files#diff-c681a9689ad6f141cb970701a07cbbc3R71

One of my worries is that since we coerce both the expected and actual value, it will be hard to catch cases were we are generating the wrong url.

Copy link
Contributor

Choose a reason for hiding this comment

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

You already commented on this in your PR message, apologies for not seeing that. Follow-up comment is below.

@stevendanna
Copy link
Contributor

Whelp, I just finally read this part of your commit message fully:

the alternate seems to be modifying a large number of tests to disambiguate the URI we use to access the system and the resource we expect to return. See the CLOUD-294/fix_tests_mechanical branch for a sense of what that might look like

That is indeed a large change; however, what I don't quite see is why we would need to add the new resource_url function vs changing api_url. If api_url was changed to do the right thing, your example branch would probably be a much smaller change.

I'm OK with merging this PR given that if fixes the problem, it just seems to me that we have a number of config items and functions trying to do the same thing in these pedant tests.

@marcparadise
Copy link
Member

I'm a little uncomfortable with this because it adds another level of hidden behaviors that aren't apparent when trying to track down failures - but given the situation, it's a reasonable fix.

markan added 2 commits April 24, 2017 16:10
This fixes two issues:

First, we were sensitive to order in the array comparator, and weren't
totally uniform in our methodology for comparing keys.

Second, and more controversially, this normalizes URIs in compared
strings. Our pedant tests frequently conflate the address the server
is listening at (platform.server) with the URI the client should
expect out of the API. This becomes important in cases like
Automate/Chef Server all in 1 installs, where the Automate service
proxies requests to the Chef Server.

This solves the problem by normalizing every appearance of
platform.server into platform.base_resource_url. An alternate solution
would be to update the pedant tests to distinquish the usages. That
would be invasive, changing many tests, and be fragile, every test has
to carefully distinguish the two useages, and we don't typically test
proxied configuration in regular Chef-Server releases.

Normalizing is both elegant and opaque. It is elegant, in that it
confines the change to just a few lines of code, and avoids the need
to be careful. However it's opaque, in that it introduces yet more
abstraction into a codebase which suffers from that already. It also
risks confusion, in that any difference report may contain
'differences' that are actually normalized away.

Signed-off-by: Mark Anderson <[email protected]>

Squash
@markan
Copy link
Contributor Author

markan commented Apr 24, 2017

I should go a little deeper into the use case to explain why I ended up here.
When we're operating in a proxied configuration, the configuration value
opscode_erchef['base_resource_url'] might be different than the actual host/port that erchef
is listening on. For example, in an automate/opsworks configuration the server might be
listening on FQDN:8443), but the correct URI to return would be
based off of the automate FQDN:443. However, the chef server tests universally use the listening
port for the server as the base for the API resources, and worse, they conflate the API to
access and the resource expected.

So we get many, many failures where we construct an expected return value using the listen
address (e.g FQDN:8443), but the return has resources correctly constructed using
base_resource_url.

Properly disambiguating that usage requires a large number of changes, and is fragile in that
we don't test proxied configurations in our mainline release path.

Pedant could be configured to address all API calls in tests to the proxied base url, but
sometimes we need the un-proxied URL (for example, when we are testing endpoints that are
not externally exposed).

Normalizing out the difference is the least fragile change at the cost of some possibly
confusing behavior.

A possible enhancement would be to add 'superstrict' as an option for the comparator, where
we would suppress this normalization and do a strict equality test.

@markan markan force-pushed the CLOUD-294/fix_tests_imp branch from cedfb67 to 92b0d2d Compare April 24, 2017 23:16
@markan markan merged commit c9141ee into master Apr 24, 2017
@markan markan deleted the CLOUD-294/fix_tests_imp branch April 24, 2017 23:42
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.

5 participants