Commit Graph

118 Commits

Author SHA1 Message Date
Monty Taylor e5d65f03d9 Retire stackforge/satori 2015-10-17 16:04:48 -04:00
Monty Taylor 1861fee39b Change ignore-errors to ignore_errors
Needed for coverage 4.0

Change-Id: I23db4005106340ac729160487a5a6c75c65b6537
2015-09-21 15:29:51 +00:00
Cian Brennan b13bbead13 Change to add install_dir to posh_ohai sysinfo provider
This is currently ignored, but is necessary for compatibility between
ohai_solo, and posh_ohai

Change-Id: I2fe04c4dce7a46028f89a61b6fce7babbf2ea2b0
2015-06-23 17:21:18 +01:00
Martin Geisler 2ff8166355 Make sure to import Posh-Ohai module in PowerShell
While PowerShell version 3 will load the module automatically,
PowerShell version 2 requires you to be more explicit.

This was missing in from 239fa1e3c7. We discovered this in
interactive debugging session with Hounsou Dansou.

Change-Id: I88db408c00b8d880cec08a14086e605e99ff8799
2015-05-26 19:08:01 +02:00
Martin Geisler 239fa1e3c7 Try parsing posh-ohai output as XML
Normally, PoSh-Ohai will return it's data as JSON. However, if
PowerShell version 3 is not available, we get data back as XML.

We now attempt to parse the returned text XML if we cannot parse it as
JSON first. We raise a SystemInfoInvalid exception if we cannot parse
the data as either JSON or XML. The SystemInfoNotJson and
SystemInfoMissingJson exceptions are no longer raised since they don't
make sense when the command can return two formats.

Change-Id: I6972595e6322d35c99fb6297565625fdb1cd951e
2015-05-26 10:32:04 +02:00
Jenkins 4b68fa3b4d Merge "Added code to set the install directory for ohai-solo" 2015-05-18 23:10:14 +00:00
Cian Brennan a21e120146 Added code to set the install directory for ohai-solo
Added options to the ohai_solo install, remove and execute methods to
allow installation of ohai-solo to somewhere other than /opt. This is
required because it lets us get around some change control policies.

Change-Id: I72d051f78c5316e6077891978c65a60ece1dd4de
2015-05-15 09:35:18 +01:00
Jenkins 60ebae7e47 Merge "ssh: fix quoting of platform_command" 2015-05-06 10:25:37 +00:00
Cian Brennan 09b6a7cd8b Fixes for pep8 tests
Pep8 tests were failing due to an error in requirements.txt
pep8 was specified as allowing from 1.5.7, with no minimum version.
Flake8 however fails with versions >1.6.
Added this requirement, and also fixed errors from pep8 tests

Change-Id: I24cb0ff34d6a28a6932a8df1206add287aca1e29
2015-05-05 11:16:41 +01:00
Jenkins c5c9a9d88e Merge "Workflow documentation is now in infra-manual" 2015-02-03 16:44:03 +00:00
Ryan Walker fd350f7f1c Refactor Popen usage to allow overrides
* Add subprocess.Popen wrapper in common
* Change bash.py and smb.py to use wrapper.

Because subprocess.Popen uses os.fork() to spawn child processes, it may
be desirable for a calling application to override subprocess.Popen with
a custom class that implements a different spawning method - such as
posix_spawn. With large-memory applications, posix_spawn may be more
desirable than os.fork() due to memory allocation behavior. This change
allows Satori to be compatible with such a workflow.

Change-Id: Ia60adea27d1a6cbf28341ea3aece5ee604a94583
Closes-Bug: #1412485
2015-01-21 10:32:31 -06:00
Martin Geisler f0e97f6e71 ssh: fix quoting of platform_command
The old code was constructing the shell command like this:

  echo -e """%s""" | python

However, shells don't do triple quoting like Python. What happens
instead is that the first pair of quotes become an empty string and
disappears. The second set of quotes quote the Python code and the
third pair of quotes also disappear.

To correctly quote the argument, one should instead wrap it in
single-quotes and take care to replace internal single-quotes with an
escaped version that first ends the previously quoted string, inserts
a single-quote and begins a new quoted string. The new shellquote
function does this.

When using this function, the -e flag is not needed or desired: it
will prematurely evaluate escape sequences that would otherwise have
been evaluated by Python.

Change-Id: I19166575b0d9b9e9836d072abab8ce0fbb2af7f2
Closes-Bug: 1401542
2014-12-11 15:29:46 +01:00
Jeremy Stanley 9b545a00b8 Workflow documentation is now in infra-manual
Replace URLs for workflow documentation to appropriate parts of the
OpenStack Project Infrastructure Manual.

Change-Id: I7ab5c3b3adf08844296e479922af8195ec7d6603
2014-12-05 03:30:46 +00:00
Samuel Stavinoha dea382bae1 interpret stderr and raise custom exceptions
1.  Detects failed authentication message from Windows systems
    and raises SatoriSMBAuthenticationException
2.  Detects error message stating that the user has been locked
    out of a Windows system and raises SatoriSMBLockoutException
3.  Detects error message stating shared access flags are
    incompatible on a Windows system and raises
    SatoriSMBFileSharingException

Consolidates (DRY) the logic which listens to command output in
smb.py so that the custom Exceptions mentioned above can be raised
if any of the known error output is encountered.

Unchanged:  A non-zero exit status with an unknown error message
            raises a SubprocessError including that error message.

Previously, all error messages corresponding to non-zero exit codes
were "unknown".

Closes-Bug: #1389034
Change-Id: I157adfe9034177f7975473ff96f29fc17c6ad12b
2014-11-06 20:23:33 +00:00
Samuel Stavinoha 5f7272abf7 Fixes interactions with popen handles
Includes logging updates and other optimizations/improvements.

Change-Id: Icf704164292637b92da25d8c720a72a5ca7c6ba6
Closes-Bug: 1381195
2014-10-29 02:03:40 +00:00
Samuel Stavinoha 453ffedabd fixes "su -" escalation
root_password was not being passed through from the RemoteClient
to the SSH client instantiation.

Change-Id: I4cd61821dd9fbe099bcdc2097807446d4072f9c4
Closes-Bug:#1362666
2014-10-29 02:03:41 +00:00
Ryan Walker 5674cbd833 Change ohaisolo and poshohai domains
This replaces the URLs for Ohai-Solo and Posh-Ohai to use a
rackspace.com domain in order to help properly identitfy the source of
the packages and prevent confusion to users on what is being done.

In the future, this URL should be fully customizable to allow for
someone to host their own Ohai-Solo/Posh-Ohai packages if they so
choose.

Closes-Bug: #1386745

Change-Id: If2b58846eb47c550614a94d73bdf33ac79ff9cf5
2014-10-28 11:18:41 -05:00
Jeremy Stanley 053cbbc815 Work toward Python 3.4 support and testing
Change-Id: I0624d09156df070238ba02576d3be627211d8900
2014-09-03 20:06:20 +00:00
Samuel Stavinoha bfb8247f54 Allow non-sudo escalations and prevent cmd dupes
If a root_password is supplied to the RemoteShell
initialization ( where applicable ), 'su -' will be
used to escalate the command, regardless of the user
that logged in. This effectively means that two passwords
may be supplied when instantiating RemoteShell, 'password'
and 'root_password'. Of course, if the username is actually
"root", the logic will infer that the corresponding password
may act as 'root_password'. The standard procedure will
be to simply use the "sudo" prefix if escalate=True on
remote_execute().

In the previous implementation, to run a command as su, you
would have to explicitly include the prefix with your command.
This change allows the executor logic to determine how to
proceed, and the caller will only need to call remote_execute
with escalate=True, like so:

    client = RemoteShell('123.123.123.5', username='bob',
                         password='bobsecret',
                         root_password='secret')
    # in this case, 'su -' will be used to escalate
    client.remote_execute('mkdir /things', escalate=True)

The second feature added to remote_execute with this change is
the allow_many keyword. To prevent your RemoteShell client from
executing the same command twice, pass allow_many=False. This
will run `ps -ef |grep -v grep|grep -c <your command>` and ensure
that the response is "0".

    client.remote_execute('echo not twice!', allow_many=False)

If the command is found to be running already, a
SatoriDuplicateCommandException will be raised.

Change-Id: I993472ecadebd67cb0bde49e692c1924c6d5c88e
Implements: blueprint allow-non-sudo-escalation
2014-08-21 19:24:12 +00:00
Samuel Stavinoha 31aa43591d add "keepalive" for remote_execute
The caller can disable this option on calls to
remote_execute() which will automatically close
the connection after successful execution.

NOTE: This is a significant logical change in the
logic of remote_execute. The previous version of
the method closed the connection *by default* each
time remote_execute was called. This changes that
behavior to be completely opposite, where the
connection will always remain open *unless* keepalive
is set to False, like so:

    # automatically closes the connection
    client.execute('echo hello', keepalive=False)

the default will keep the connection alive:

    # both commands run on the same transport instance
    client.execute('echo hello one')
    client.execute('echo hello two')

This change also adds the context managers to RemoteShell,
so that you can ensure that the connection will be closed
without having to rely on the controversial __del__(), which
has also been implemented for RemoteShell in this submission.

To use the context manager ( with statement ):

    with RemoteShell('123.123.123.2') as client:
        client.execute('echo hello')
        client.execute('echo again')

The sysinfo providers will now use the context manager
implementation. See `get_systeminfo` in ohai_solo.py
and posh_ohai.py

Change-Id: I267f7efe0f588c5bdc83b419c01997a69378c308
Implements: blueprint remain-open-post-remote-execute
2014-08-20 20:28:40 +00:00
Nico Engelen b778d8165a Move serviceinstall to satori
This change is to remove the dependency on a custom version of impacket.
This dependency was necessary because the serviceinstall example inside
impacket did not support custom service/executable names but always
generated a random name for both and a change of the example was very
unlikely to be merged upstream.

Further to that, two minor bugs were fixed
 - satori.smb.SMBClient.create_tunnel() was calling
   satori.tunnel.connect() which has been removed, this has been
   changed to now use the constructor: satori.tunnel.Tunnel()
 - satori.tunnel.Tunnel.serve_forever() was calling self.start
   instead of self.tunnel_thread.start()

Minor style fixes have also been made. Further to that, the
serviceinstall example is not provided under an Apache2 license and
therefore H102 needs to be ignored by tox.

Change-Id: I04f48bf08f9361833cb607faa74ece26a48ea02d
2014-08-01 17:29:34 +01:00
Samuel Stavinoha 6cabc1773d Adds Windows Support to satori discovery
This change adds the capability to satori to do data plane
discovery on Windows devices. For that, a class has been
added that mirrors the functionality of satori/ssh.py and
utilizes a "3rd party" script (satori/contrib/psexec.py)
which is called via subprocess.Popen(). Further to that, an
SSH tunneling class has been put in place that uses paramiko
to establish a tunnel (similar to running ssh -L from a shell).
requirements.txt has been extended to include impacket which
satori/contrib/psexec.py imports.

Move support for PoSH-Ohai into its own provider module.
Raise UnsupportedPlatform exceptions in ohai_solo.py
when the client is non-linux, and raise the same
exception in posh_ohai.py when the client is non-windows.

Co-Authored-By: Nico Engelen <engelen.nico@googlemail.com>
Co-Authored-By: Samuel Stavinoha <samuel.stavinoha@rackspace.com>
Change-Id: I7a94eea9446bc7f57843407fb98880222f7af6af
Implements: blueprint windows-support
2014-07-29 03:14:22 -05:00
Jenkins 078468a468 Merge "Update requirements file" 2014-07-28 16:59:01 +00:00
Longgeek bc9c9fbab4 Update requirements file
* Add the argparse module
Change-Id: Ib2beef9dc1e9c76e26b4b06b43693772f6b62af3
2014-07-28 19:02:31 +08:00
Samuel Stavinoha e7aee8a7cd fix tests and test requirements
Changes to python-whois require updates to dns unittests.

Updates pep8 requirement from jcrocholl/pep8 Issue#240:
    Fix was merged into pep8 1.5.7
Updates hacking requirement to fix VersionConflict

Change-Id: I44deeb5f7b164f6a40d4eabc68630f373ea2167a
Implements: blueprint dependency-fix
Closes-Bug: #1347093
2014-07-22 23:07:38 +00:00
Samuel Stavinoha dca1d8d28a reimplement ssh proxying using ssh transport
Removes fragile, bulky code and provides a more robust solution,
as well as negating the depedency on a local ssh program.

Coincident updates:
- renames keyword argument 'proxy' to 'gateway' and updates
  close() method to handle the closure of that connection as well
- renames underlying RemoteShell client to _client attribute
    - uses this attribute to access methods

Change-Id: Ie1ce9f19fbe5bb4341fb6721e3069c1d267be95f
Implements: blueprint reimplement-ssh-proxy
2014-05-27 13:47:14 -05:00
Ziad Sawalha c382a3e860 Implement New Discovery Schema
Change-Id: Ibd34c44211920197cf19df535ef038279fff2714
2014-05-07 15:25:05 -05:00
Samuel Stavinoha ae4bc4ebb7 Unittests for satori-localhost implementation
Change-Id: Ica67b3541875e3fdd6ca99ea34cddc105bdeec12
Implements: blueprint satori-localhost
2014-05-05 22:49:21 -05:00
BK Box 199bba3095 Add `ip_info` and `netloc_info`
`domain_info` makes the assumption that only a domain is being passed to
it. This patch adds an `ip_info` and a `netloc_info` to handle ip
addresses or domain.

`ip_info` expects an IP only and will error if the string that is
passed to it is not a valid IP address.

`netloc_info` will attempt to determine if the string that is passed to
it is an IP or a domain, and call the appropriate function.

Change-Id: I34baf3b2ee94bd866531f94d3073fe83098f1046
Implements: blueprint ip-and-netloc-info
2014-04-14 09:07:17 -05:00
Jenkins 1b82964f41 Merge "Update pythonwhois to py3 compatible version" 2014-04-07 22:53:05 +00:00
Ziad Sawalha c6cabcff0e Update pythonwhois to py3 compatible version
Change-Id: Id24b8ab334160749683659ebf72a2a19a6b1e535
2014-04-03 11:17:24 -05:00
Samuel Stavinoha 54f816aa1f Fix remaining refs to the former config object
Switch notation from

    value = d.key

to

    value = d.get('key') # in optional cases
    value = ['key'] # in required cases

Unittests for config dictionary make use of mock.patch.dict

Change-Id: Ib688dd13e1e3df9a82b3f0377064be8e6c765e55
Closes-Bug: #1301020
2014-04-01 16:54:03 -05:00
Jenkins 70cc26801f Merge "Add exception `SatoriInvalidDomain`" 2014-04-01 16:02:01 +00:00
Caleb Groom d80e65b73a Convert configuration object to a dictionary
This change no longer requires users of the Satori module to fake
an argparse object to set configuration values.

Change-Id: I61a1086bf16befe3dc9e45ba739790ed99eeb446
Implements: blueprint poc-config-object
2014-03-26 11:23:20 -05:00
BK Box d649f19680 Add exception `SatoriInvalidDomain`
When `domain_info` is passed an invalid domain, it would attempt to
parse the registered domain and eventually pass a blank string to
`pythonwhois.get_whois`. This causes an exception of "No root WHOIS
server found for TLD." This is a valid exception, but we should not make
it this far to get this exception.

Instead, this patch will raise an exception of `SatoriInvalidDomain` if
domain_info attempted to be used with an invalid domain.

Change-Id: Ie30b9a01b39d92d8bfeb7f3a80d333fa4bb30d49
Closes-Bug: #1295391
Closes-Bug: #1293670
2014-03-25 10:24:17 -05:00
Jenkins c9fef42b4e Merge "Cleanup for another release" 2014-03-25 00:33:09 +00:00
Ziad Sawalha a5b9c4df38 Cleanup for another release
Relax requirements to simplify installation

Bumped version by version until an error appeared.
I did this per dependency, so I did not take into
account any incompatibilities between specific
versions of dependencies.

Change-Id: I59b5d386c674e628924909348a38966b76ae88dc
2014-03-24 17:02:47 -05:00
Jenkins e7109d780f Merge "Documents OpenStack control plane discovery" 2014-03-21 17:49:23 +00:00
Caleb Groom f414d0acfd Documents OpenStack control plane discovery
Change-Id: I51ddb2477fbaa0215d6621f31d0f7189c8350bac
2014-03-20 21:55:29 -05:00
Caleb Groom 7a11714010 Only attempt remote logins if directed by the user
Since the system info plugin was defaulting to ohai-solo this
commit moves the check for the user's intention up.

Change-Id: Iccbbd882371131c930f7a951cc88c5628c290464
Closes-Bug: 1295315
2014-03-20 15:25:53 -05:00
Samuel Stavinoha 01ad34c89f Allow running satori on localhost
Still needs unittests

Change-Id: Ia6bf6f5d1e4bcadb414eb79bb9673fbc60d1c9a6
Implements: blueprint satori-localhost
2014-03-20 02:11:47 -05:00
Jenkins 3e245d4849 Merge "Install python-novaclient 2.15.0 and newer on PY3" 2014-03-20 04:48:38 +00:00
Jenkins 7c13bfed45 Merge "Pull out JSON string from stdout" 2014-03-20 04:46:58 +00:00
Ziad Sawalha a4a2a27a8d tests: fix mock usage
Change-Id: I38bef45b09c5e90e079fcf0d4fdaf796bf79b79a
2014-03-19 17:14:06 -05:00
BK Box 76203fe518 Install python-novaclient 2.15.0 and newer on PY3
All versions before 2.15.0 are not compatible with python 3.3. This
change will restrict to that version or newer for python 3 only. PBR
will look at requirements-py3.txt, if present, and install a newer version
of python-novaclient.

Change-Id: I00298dcd2e479f0683bf7884e68e88912a5cb1b7
Implements: blueprint relaxed-novaclient-version
2014-03-19 16:59:49 -05:00
BK Box 0258742b74 Pull out JSON string from stdout
When there is a custom message in `.bashrc` on certain fedora based
distros, the string will be included in the stdout. This will pull out
the following JSON string, if present, and attempt to parse that.

Change-Id: I7d0d4e9b36924664d158c62baf8cdef163bd1d85
Closes-Bug: #1294851
2014-03-19 15:42:01 -05:00
Caleb Groom 6441192a98 Move IP testing functions to satori/utils.py
Other modules could want access to these functions in the future
and this cleans up satori/discover.py.

Change-Id: I6954e073c16150e90525218d1d8a15525db70110
2014-03-19 09:51:26 -05:00
Ziad Sawalha f6141a6773 docs: autogenerate docs w/ module docstrings
Change-Id: I89c5982ceb9606b462a140ea2ea664615245e93e
2014-03-19 08:51:10 -05:00
Jenkins 0d3636acc4 Merge "Implement ohai-solo data plane discovery module" 2014-03-18 22:50:18 +00:00
Ziad Sawalha 7be1d3d0c2 Implement ohai-solo data plane discovery module
This is a prototype of a discovery module that
connects to a server and gathers information about
how it is configured.

Change-Id: Ide2d75769ae21befcab6886b9cfd12b7ef19ea8d
2014-03-18 17:15:08 -05:00