98 Commits

Author SHA1 Message Date
Steve Baker
ad475ee927 Collector which does a simple HTTP GET
This change implements a collector which does an HTTP GET via
python requests to fetch the metadata.

It should work with any GET-able URL, however it is designed to
work with Swift TempURLs.

Swift objects are not consistent, so the Last-Modified header is
checked for each poll and metadata is not fetched if the last
modified is not newer than the previous successful poll.

This collector will be enabled for OS::Nova::Server
software_config_transport: POLL_TEMP_URL which is available
in the Juno release of Heat. Using POLL_TEMP_URL will result
in no metadata polling load on heat, which has historically been
an issue with tripleo scalability.

Change-Id: I22155c22bdcc3c81a5e945ca5436a8f29f196528
2014-10-17 09:40:23 +13:00
Gregory Haynes
6d32511dd0 Exit with error status on failed command
When we detect a failed command we log ERROR but we do not return an
error status. This makes it difficult for programs which may run
os-collect-config to detect whether a run was sucessful.

This only applies to runs which are performed with --one-time argument
as this is a straightforward case.

Change-Id: I168862e8c75c15d1ea405a417908d1284feb7b32
2014-10-09 00:20:03 -07:00
Gregory Haynes
7e913145a3 Fix py3k popen and locale test fails
A popen call is made in the Python 3 platform module which causes our
assertions for our mock'd popen to fail. Also fixing a locale issue to
use defaultlocale() rather than LC_ALL.

Co-Authored-By: Steve Kowalik <steven@wedontsleep.org>
Change-Id: I45cdf7d921fbca5f09e5f65bd69fcee83fb7c8e4
2014-10-09 00:17:43 -07:00
Yanyan Hu
47bb4bddb2 Using keystone discover to find V3 auth_url
This patch uses keystone client discover to find correct V3
auth_url which is expected by heat collector.

Change-Id: I2b8b5a768bdeb1cd1d20fab3b4234306c1429d6d
Closes-Bug: #1341936
2014-09-03 01:46:35 -05:00
Jenkins
7d61ca940c Merge "Add support for Python 3" 2014-09-02 10:17:38 +00:00
Jenkins
5af061bc79 Merge "Sync log from oslo" 2014-09-02 09:09:08 +00:00
Steve Kowalik
a3c1159ed4 Add support for Python 3
Make changes pretty much all over the code base with respect to
encoding strings and fixing imports to support Python 3.

Change-Id: Id1920129001b8e223474c1b2faf8bd9d527fe7e7
2014-09-02 16:56:18 +10:00
Steve Kowalik
a776aeace9 Sync log from oslo
Update the copy of oslo's log to oslo-incubator
0533894d6bfacd82a371bccd628b61d5016032cd.

This is the first step towards supporting Python 3 in
os-collect-config.

Change-Id: If282091d7f0cbd4e2ce90d70c066bb11cbf56d38
2014-09-02 15:22:22 +10:00
Clint Byrum
9cb442e93c Allow using non-default collectors
The local collector is not in DEFAULT_COLLECTORS, but should be usable
explicitly. It, however, suffers from a bug where only
DEFAULT_COLLECTORS are allowed through.

Change-Id: Ia42d1acd39638b448e2e2bfa26aff1c7ae415b71
2014-08-19 22:24:18 +00:00
Jenkins
9b28e39fa1 Merge "Add a local data collector" 2014-08-08 16:59:35 +00:00
Clint Byrum
4696fd4f93 Add a local data collector
This collector will collect data from the local system, allowing image
builds or simple processes to influence the metadata.

implements bp tripleo-juno-occ-localdatasource

Change-Id: I0e58e8c631ffe8b63e8b4117df2c9ce2f413044f
2014-08-08 07:30:11 -07:00
Clint Byrum
79efeba4c3 Do not log unconfigured collector as warning
The configuration will dictate whether or not something is configured.
If it is not, this is a normal state and should not be logged as a
warning.

Change-Id: I479f0aed5837871009bc69fa028f5eb64a060c53
Closes-Bug: #1321551
2014-07-21 13:54:48 -07:00
Clint Byrum
42efe2b969 Revert "Make heat the default collection method"
This reverts commit 6b478e9d90bce18b03f5411822897740f68c3dd0.

We will break anybody who is expecting CFN to be tried in all
circumstances with this. We probably just need to base which collectors
to try on what configuration we have, and not log warnings on
unconfigured collectors.

Change-Id: I4bf7d6f9af9487bf9d2c0942381c0ba68fc03ee9
2014-07-08 14:04:42 -07:00
Clint Byrum
6b478e9d90 Make heat the default collection method
Previously we were relying on the CFN compatibility API. This makes the
native Heat version the default.

Note that we want to keep full coverage, which is why we are explicitly
adding cfn back in during tests.

Change-Id: I5adedd052827e176e2f39071c719600df62019d7
Closes-Bug: #1321551
2014-07-03 10:22:06 -07:00
Clint Byrum
ee911cfb69 Cache auth_ref from keystoneclient
Auth_ref is documented as a serializable object which we can save off
and use to reinitialize keystoneclient. That should in turn be passable
to heatclient directly. With this code, we will avoid authorizing with
Heat if we have a token in the cache.

Change-Id: I3dc6c3726054e77449cc9be46229e6d3521d4ef2
Closes-Bug: #1321437
2014-07-03 10:21:51 -07:00
Clint Byrum
328e1c6cfe Add dogpile cache to keystone abstraction layer
In later commits we will use this cache to memoize access to the
authentication details.

Change-Id: I389f78fe1eb176e37c90a1a87a4ba5fde3b33f05
Related-Bug: #1321437
2014-06-27 23:18:07 +01:00
Clint Byrum
1dc89292dc Split keystone away from heat collector
This will help segregate the changes as we abstract away details of
keystone such as caching the tokens.

Change-Id: I81ccb17658e5c9fa349fb183240f901d61b1fa93
Related-Bug: #1321437
2014-06-27 23:17:39 +01:00
Clint Byrum
dc35d20358 Use json equality rather than raw text
It turns out sometimes json will serialize differently given the same
python structure. A check of the two parsed data structures will detect
changes more reliably.

Change-Id: Id165b36c0fa0fa89730c3507444a41c68bd70fb3
Closes-Bug: #1320262
2014-05-22 12:13:08 -07:00
Steve Baker
b066d4cc85 Only top-level some deployment configs
Only config which contains os-apply-config data should be written
to the top level config structure. This change will only top-level
configs which are in the group os-apply-config or the default group
Heat::Ungrouped.

This tripleo-heat-templates change will specify a group for all
config resources https://review.openstack.org/#/c/91731/ however
the expected top-levels will still be written out without this
change.

This change is to fix heat software config when the config is not
json.

Change-Id: I16e42825121cf4968d4b0f0d266f4f6daa962921
Closes-Bug: #1299109
2014-05-08 12:32:25 +12:00
Jenkins
08a3237484 Merge "Add collector for heat API resource metadata" 2014-04-29 20:43:34 +00:00
Jenkins
87b0fc4049 Merge "Restore 'deployments' key to cfn Metadata" 2014-04-17 19:56:29 +00:00
Steve Baker
80c98a33ee Add collector for heat API resource metadata
This collector uses keystoneclient and heatclient to poll for the
configured resource metadata.

Changes were required to test_collect to allow collectors which needed
to fake something other than requests.

Change-Id: I3e93fe38b15f71193a4c024b24e6260d6adcf1b3
2014-04-16 11:50:57 +12:00
Clint Byrum
6198acbfcc Commit changes to exploded deployments to cache
Before this, the exploded deployments that the cfn collector produced
would not ever be committed, and thus would always appear to have been
changed. This resulted in os-collect-config running the command
endlessly.

This requires some refactoring so that we commit changes to the cache
based on what was actually written, rather than just the static list of
collectors.

Closes-Bug: #1307153

Change-Id: I618ef5d752ed6519e8b7bfc090de03f2f24e73ce
2014-04-13 14:55:18 -07:00
Clint Byrum
77fb0651bc Test that collect_all works when nothing changed
This improves the test coverage for this very common case and sets up
for a new test which will expose that we fail in this case for exploded
deployments collected by the cfn collector.

Change-Id: I74807107824f8795619207389c064e83580c1c87
Related-Bug: #1307153
2014-04-13 09:55:58 -07:00
Clint Byrum
345443c88e Cover deployments explosion case better in tests
When cfn explodes deployments we end up with many things stored per
collector, so some assumptions around 1:1 collector to cached content
cannot be made anymore.

Change-Id: I43c5fb759bc99690e0def1c6ecb672ab7f087df8
2014-04-13 09:34:48 -07:00
Clint Byrum
8cfe571c70 Restore 'deployments' key to cfn Metadata
In recent changes support was added to explode the deployment key into
multiple json files for merging by os-apply-config. But this breaks
other users who want direct access to the full deployments structure.

There seems to be no real reason to delete the key other than tidiness,
so we will stop deleting it from the main cfn structure.

Change-Id: Icf9479376e32c3ad8f9be29359e6100c1aeda2a5
Closes-Bug: #1299110
2014-04-01 16:18:11 -07:00
Clint Byrum
831ab0be03 Parse deployments if found in cfn metadata
Will result in multiple cache files to be merged per
OS::Heat::StructuredDeployment. This is needed as the new features for
software configuration break things up a bit differently in Metadata.

Change-Id: Iec0fd947bac674f6b6f36e8c0789d10580c325fd
Closes-Bug: #1295787
2014-03-24 10:46:44 -07:00
Clint Byrum
16158684a6 Change collector interface to return a list
With the new OS::Heat::StructuredDeployment resource, each Metadata
section may have multiple "deployments" in it. With this, we will return
a list with tuples of key and content to write to the cache.

Change-Id: I9f4272b0761e1dfd850bc5a5c6b27a78f126281f
Related-Bug: #1295787
2014-03-21 14:54:46 -07:00
Clint Byrum
8f095feee6 Move default cache dir to persistent location
While this is called a "cache", it is important for it to survive. On
reboot, servers may need what was in the cfn config to restore complex
network configurations.

We introduce a new command line option, --backup-cachedir, that will
default to the old path, /var/run/os-collect-config. This will keep
things working for any tools that have been hard coded to use the old
path.

Change-Id: I78b3851b35addfc16913e3cd53c9d0e7eb3d191a
2014-01-22 12:16:37 -08:00
Mark McLoughlin
a479edb493 Log the value of OS_CONFIG_FILES
We pass the list of json files containing the collected metadata to
os-refresh-config using the OS_CONFIG_FILES env variable, so it's a
pretty useful piece of information to log.

Change-Id: Id09e3f352e6a5a09e4183c0743a6e99a2783a888
2013-12-17 07:59:17 +00:00
Ghe Rivero
48ff408222 Comply with new hacking requirements
With new hacking>=0.8.0,<0.9 requirements, some functions are
now deprecated.

assertEquals -> assertEqual
assertNotEquals -> assertNotEqual

Change-Id: I70287b0c8561a901069bddcf3007751c34a4e0b5
2013-11-18 12:37:15 +00:00
Clint Byrum
69d74dde12 Reduce default polling interval to 30 seconds
The initial value of 300 seconds was a conservative estimate. However,
the requests and responses are somewhat small, so we can drop the polling
interval significantly and still maintain a high degree of network
scalability. After measuring the responses from the ec2 and cfn servers
with typical workloads, at 30 second intervals 100 servers will generate
around 26kB/s of requests, with about 66kB/s of responses.

Change-Id: Iaa99ae405ba7c72ef8afc11c946400a2d0db5206
2013-10-25 09:38:13 -07:00
Clint Byrum
e82a98f127 Imply --one-time when --force is used
Without this change, if a user runs os-collect-config --force, it will
lock the user in an infinite loop running the command over and over with
very little chance to cancel. There are no compelling use cases for that
behavior, but it is extremely inconvenient, so implying --one-time
improves usability of os-collect-config for users.

Change-Id: Ia8c9bf0bf97ab9e40e465c947c2f0cbeb981c08e
2013-10-05 23:39:49 -07:00
Clint Byrum
db896fdf3a Make --version work properly
We have pbr and we have oslo.config. Tell them about eachother.

Change-Id: I65d449b0ed961c824a3e7c1307aab63f73bc03ad
2013-09-17 17:30:52 -07:00
Clint Byrum
635955def4 Add --print option to force printing
The use case for --print is an administrator wanting to view the
metadata that os-collect-config sees without running any commands.

Fixes bug #1213195

Change-Id: I0251f2c70574aeaa79997ce822d2a5ffbe08e345
2013-09-16 12:35:25 -07:00
Clint Byrum
c1e60159f5 Add a --force option
This is a useful debugging and/or system fixer tool for instances where
metadata has not changed but one needs to re-run the configuration.

Fixes bug #1223693

Change-Id: I62b097bafa339fefcf6e03d11636f5ab622fb71a
2013-09-13 07:52:58 -07:00
Clint Byrum
6eb8eb9af3 Store list of collected configs in cachedir
This will allow tools like os-apply-config to read the list even when
they are run out of band from os-collect-config.

Change-Id: Ic4eaf649e234f4a1367d20c7ec52e93e787a7bb3
2013-09-13 00:39:49 -07:00
Clint Byrum
c2b1b3909c Add --print-cachedir option
The option allows other programs to find the cache directory and files
without having access to OS_CONFIG_FILES.

Change-Id: Iad87efb65ea4db387e94160376c9eaf956fff413
2013-09-13 00:33:14 -07:00
Derek Higgins
61b6dfb604 Replace tearDown with NestedTempfile Fixture
Teardown isn't called if Setup errors, this should be more reliable.

Change-Id: I7804738527b1da18908652cf5dee591d75fa66b5
2013-09-03 20:50:14 +01:00
Derek Higgins
4cfeb28d12 Rerun os-collect-config if config changed
Keep a hash of the config file for os-collect-config and if it changes
during a failed run then rerun immediately(without sleep), effectively
causing new nodes to be ready 5 minutes earlier.

Because the cfn credentials are placed into os-collect-config.conf by
os-apply-config and are not in place the first time os-collect-config is
run, the first run of os-collect-config results in error, o-c-c then
sleeps for 5 minutes before running successfully the second time.

Fixes bug #1219186

Change-Id: I090de7a3d84e0ea342f1a422646c0c455eb37f4a
2013-09-03 13:35:55 +01:00
Derek Higgins
bbb1c77106 Setup loghandlers in o-c-c binary
On a system with o-c-c installed by pip the binary generated by PBR
calls __main__() directly, the code that sets up logging sould be placed
here otherwise it will be bypassed. Resulting in missing log messages.

Change-Id: I94ba4f61be9595a6ddee134d806e5f99ae4adf73
2013-09-02 17:01:58 +01:00
Robert Collins
5b8fd361c2 Stop resetting logging on every call to __main__.
__main__ is called directly during tests, but was resetting the
logging environment within it, which prevented tests from capturing
the log events.

Change-Id: If710e11091723144c97c88aab4aa5e6126844d2b
2013-08-16 17:29:58 +12:00
Robert Collins
f20f9954db Stop using tearDown.
TestCase.tearDown doesn't get called if setUp fails, it should never
be used.

Change-Id: Ib960c3f9610d8d8a0624e0c0709afa819e1858ad
2013-08-16 17:29:58 +12:00
Clint Byrum
1897ecf001 Do not cache new data if command fails
The point of delaying the commit of data to the cache is that we want to
make sure the command succeeds before giving up on the data changes.
This will ensure that we keep trying the command with any given change
to the metadata until it succeeds.

Change-Id: Idf3a09686b4bbf0e16a9bc9f3359ee9937fcc627
2013-08-16 17:29:58 +12:00
Robert Collins
4bdefc2041 Document the last file presence.
Smart hooks may want to perform delta analysis on metadata, and tests
want to be able to tell if the cache is updated it's previous state,
so we should make the presence and name of the old versions of the
files a stable interface.

Change-Id: Ia29c1ef9e10308d6461dae7823c5f497f6b90122
2013-08-16 17:29:58 +12:00
Robert Collins
98c8588867 Switch to StringStream.
In Python 3 stdout is a text stream not a byte stream, so we should be
prepared for that.

Change-Id: I4bc1151e491226f24591e9b3436db8d5d37fca65
2013-08-16 17:29:58 +12:00
Robert Collins
def1daa155 Rework test_main to use FakePopen.
FakePopen will make the migration to check_call easier, and narrowly
replaces the engire rather than replacing the subprocess entry point.

Change-Id: Ic868ce4cdbef79f256ef01a9a030767522b855a3
2013-08-16 17:29:55 +12:00
Clint Byrum
13b6732546 Reverse default order of collectors.
The default order results in less-dynamic heat_local and ec2 overriding
the more dynamic cfn source. That is the opposite of what is desired.

Change-Id: I7e1feb2e6869b4f076200668dd204219ecc4224e
2013-08-15 11:22:50 -07:00
Jenkins
bf31e030c4 Merge "Fix a hacking complaint" 2013-08-06 07:08:37 +00:00
Robert Collins
e017b0d09f Fix a hacking complaint
We can't land changes while hacking is unhappy.

Change-Id: I8ae913a965cd9be1fecec9ea960b90c8a69dca2b
2013-08-06 16:14:55 +12:00