Commit Graph

271 Commits (37052a983a7f37e5f7e8c03e1ed75fe89d4a58bd)

Author SHA1 Message Date
Abhijit Menon-Sen 7479ab47e0 Be stricter about parsing hostname labels
Labels must start with an alphanumeric character, may contain
alphanumeric characters or hyphens, but must not end with a hyphen.
We enforce those rules, but allow underscores wherever hyphens are
accepted, and allow alphanumeric ranges anywhere.

We relax the definition of "alphanumeric" to include Unicode characters
even though such inventory hostnames cannot be used in practice unless
an ansible_ssh_host is set for each of them.

We still don't enforce length restrictions—the fact that we have to
accept ranges makes it more complex, and it doesn't seem especially
worthwhile.
9 years ago
Abhijit Menon-Sen 065bb52109 Be systematic about parsing and validating hostnames and addresses
This adds a parse_address(pattern) utility function that returns
(host,port), and uses it wherever where we accept IPv4 and IPv6
addresses and hostnames (or host patterns): the inventory parser
the the add_host action plugin.

It also introduces a more extensive set of unit tests that supersedes
the old add_host unit tests (which didn't actually test add_host, but
only the parsing function).
9 years ago
Marius Gedminas f91b28ef23 Fix safe_eval() of set literals
There was code to support set literals (on Python 2.7 and newer), but it
was buggy: SAFE_NODES.union() doesn't modify SAFE_NODES in place,
instead it returns a new set object that is then silently discarded.

I added a unit test and fixed the code.  I also changed the version
check to use sys.version_tuple instead of a string comparison, for
consistency with the subsequent Python 3.4 version check that I added in
the previous commit.
9 years ago
James Cammarata 444987cde6 Fix unit test for plugins after basedir/push_basedir removal 9 years ago
Toshio Kuratomi e2c49b4ef4 Fix problem with "=" in the initial file path. 9 years ago
Toshio Kuratomi 3a50393cf7 Merge pull request #12269 from mgedmin/py3k
Python 3: fix TypeError: unorderable types in test
9 years ago
Toshio Kuratomi c1039de70c Compatibility with six-1.3.0 9 years ago
James Cammarata ac6f61ec7f Properly handle group/host_var files with dots in them
Fixes #12245
9 years ago
Marius Gedminas c22f4ee697 Add a comment explaining why async = 1 in the test 9 years ago
Marius Gedminas 1a1c9203e2 Python 3: fix TypeError: unorderable types in test
The full error was

======================================================================
ERROR: test_task_executor_execute (units.executor.test_task_executor.TestTaskExecutor)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/mg/src/ansible/test/units/executor/test_task_executor.py", line 252, in test_task_executor_execute
    mock_action.run.return_value = dict(ansible_facts=dict())
  File "/home/mg/src/ansible/lib/ansible/executor/task_executor.py", line 317, in _execute
    if self._task.async > 0:
TypeError: unorderable types: MagicMock() > int()

----------------------------------------------------------------------

Experiments show that Python 2 MagicMock() > 0 is true, so I'm setting
the async property on mock_task to 1.  (If I set it to 0, the test fails
anyway.)
9 years ago
James Cammarata ff9f5d7dc8 Starting to add additional unit tests for VariableManager
Required some rewiring in inventory code to make sure we're using
the DataLoader class for some data file operations, which makes mocking
them much easier.

Also identified two corner cases not currently handled by the code, related
to inventory variable sources and which one "wins". Also noticed we weren't
properly merging variables from multiple group/host_var file locations
(inventory directory vs. playbook directory locations) so fixed as well.
9 years ago
Brian Coca c17fbf2f12 simplify become testing and handling, we had drifted and were doulbe checking prompt, become and become_pass
fixed tests to conform to new signature and now tests both with and w/o password
now we are more explicit about self.prompt
9 years ago
Toshio Kuratomi e218bf8da9 Do not escape backslashes when processing a template file.
Fixes #12198
Fixes #12241
9 years ago
James Cammarata b2cb3153f1 Fix unit tests for PlayIterator changes regarding fact gathering 9 years ago
Marius Gedminas a32bf1ec18 Simplify FactCache.copy()
Also fix the bug (missing from six import iteritems) I introduced in
823677b490.
9 years ago
Marius Gedminas 823677b490 Replace .iteritems() with six.iteritems()
Replace .iteritems() with six.iteritems() everywhere except in
module_utils (because there's no 'six' on the remote host).  And except
in lib/ansible/galaxy/data/metadata_template.j2, because I'm not sure
six is available there.
9 years ago
Toshio Kuratomi 1b64702b9a Fix templar unittests for change in preserve_trailing_newline parameter's default value 9 years ago
James Cammarata 45aac6a739 Adding unit tests for safe_eval 9 years ago
James Cammarata 843138e7d9 Merge pull request #12202 from mgedmin/py3k
Use rich comparisons for Attribute and FieldAttribute
9 years ago
Toshio Kuratomi 9ecfc30f9a * Mark all strings as unicode -- shouldn't matter for this dataset but
ansible is passing unicode arond internally so we should test the same
  data.
* Add a zero length test for _count_newlines and fix the zero newlines
  test to have no newlines.
9 years ago
Toshio Kuratomi 417bf1c805 Unittest the _count_trailing_newlines function 9 years ago
Brian Coca a7231c2203 actually implemented flags correctly for all priv escalation methods 9 years ago
Brian Coca 14f061d5ea fixed become tests 9 years ago
Marius Gedminas 33a374edde Use rich comparisons for Attribute and FieldAttribute
Because __cmp__ is not supported on Python 3.
9 years ago
Toshio Kuratomi aeff960d02 Cleanup combine_vars
* Dedupe combine_vars() code (removed from VariableManager)
* Fix merge_hash algorithm to preserve the type
* unittest combine_vars and merge_hash
9 years ago
Toshio Kuratomi 7f5080f64a Fix backslash escaping inside of jinja2 expressions
Fixes #11891
9 years ago
James Cammarata ccaf47bd97 Fix unit tests broken by 057712c1 9 years ago
Marius Gedminas 709dbbc7db Use 0oNNN octal syntax in test/ 9 years ago
Abhijit Menon-Sen 4f3a98eff6 Update Vault tests to make sure AES decryption works
Note that this test was broken in devel because it was really just
duplicating the AES256 test because setting v.cipher_name to 'AES'
no longer selected AES after it was de-write-whitelisted.

Now that we've removed the VaultAES encryption code, we embed static
output from an earlier version and test that we can decrypt it.
9 years ago
Abhijit Menon-Sen b84053019a Make the filename the first argument to rekey_file 9 years ago
Abhijit Menon-Sen c4b2540ecc Update tests for VaultEditor API changes 9 years ago
Toshio Kuratomi 56ae3a032f Merge pull request #12075 from ansible/fix-vault-unicode
Unicode and other fixes for vault
9 years ago
Toshio Kuratomi a3fd4817ef Unicode and other fixes for vault 9 years ago
Brian Coca 846f0b0510 changed no_log expected type to new value 9 years ago
Ryan Petrello 1886307845 Fix a parsing bug that prevents IPv6 addresses from being used with `add_host`
Closes #8682
9 years ago
Brian Coca 69f380da3a changed mod_args test to match connection 9 years ago
Brian Coca ab355218a0 fixed test to new parser options 9 years ago
Brian Coca ee21ebaffc Merge pull request #11975 from mutemule/become_doas
Add become support for OpenBSD doas
9 years ago
Damian Gerow 1c5611100e Add become support for OpenBSD doas 9 years ago
Brian Coca 43bf9c86d8 fixed typo 9 years ago
Brian Coca d38bb4152d fixed test to match new exception class used 9 years ago
Brian Coca 2eb5333b50 fixed test to match new become output 9 years ago
Toshio Kuratomi e8452c864e Restore the relative path handling portion of #11865 9 years ago
Brian Coca b9433650d1 Revert "Path of group_vars and host_vars were getting the basedir added twice."
in view of simpler solution incomming from james
This reverts commit bae7a02be5.
9 years ago
Toshio Kuratomi bae7a02be5 Path of group_vars and host_vars were getting the basedir added twice.
Fix inventory so this won't happen and fix DataLoader so that it will
test relative paths relative to self._basedir

Fixes #11789
9 years ago
James Cammarata 9891bcbcae Fix unit tests broken by previous commit 9 years ago
James Cammarata 6b244ed61e update unit tests for role templating changes 9 years ago
James Cammarata 42cfacf83b Switch up the task/host overrides for PlayContext to use the compiled vars dict
Fixes #11436
9 years ago
James Cammarata 8146a193eb Fix strategy base unit tests after 88e1ef8 9 years ago
James Cammarata 993ce592b1 Update unit tests for flush_handlers fix 9 years ago
James Cammarata 66a8864ae9 Fix environment setting and inheritence
Fixes #11401
9 years ago
James Cammarata e64989beb4 Moving ConnectionInformation -> PlayContext
Also making PlayContext a child class of the Playbook Base class,
which gives it access to all of the FieldAttribute code to ensure
field values are correctly typed after post_validation

Fixes #11381
9 years ago
James Cammarata fadd8f23f1 Fix broken strategy unit test from earlier change 9 years ago
Pierre-Louis Bonicoli 8c392a94b7 Play.get_name: remove prefix, return name only 9 years ago
James Cammarata 3d77723e3d Cleaning up some stuff related to the connection info/become/executable change 9 years ago
Brian Coca 323362e23a added stdout to test result 9 years ago
James Cammarata 3b913943b2 Updating base strategy unit test regarding bad file loads based on earlier change 9 years ago
James Cammarata 1163e38d39 Fix unit tests for new magic variable addition 'ansible_version' 9 years ago
James Cammarata bbe8f48a46 Update role unit tests for changes made to require a play during loading 9 years ago
marconius 79394f5c8f Added tests for `taggable` module 9 years ago
James Cammarata bfbb88b4a9 Fix strategy plugin unit tests related to earlier changes 9 years ago
Toshio Kuratomi f44f9569e1 Test unquote works as expected and fix two bugs:
* escaped end quote
* a single quote character
9 years ago
Brian Coca aa6486778f fixed become test to match new expected output 9 years ago
James Cammarata 53cd96befe Updating unit tests to account for new magic variable 'vars' 9 years ago
Matt Martz 2cd3a1be00 assertRaises should be given an exception type. Fixes 11441 9 years ago
James Cammarata 4fbd4ae18b Update VariableManager test for additional magic variable playbook_dir 9 years ago
Brian Coca 5bac17de51 fixed pfexec test 9 years ago
Brian Coca 091caf6279 added missing error class import 9 years ago
Brian Coca e9cf67004b updated fail_on_undefined test to new function signatures 9 years ago
Matt Martz 230be812ba Don't test for play.become_pass any longer 9 years ago
Matt Martz 49d19e82ab Get tests passing
The largest failure in the tests was due to selinux not being installed.
The tests don't require it to be installed, so mock the import.
9 years ago
James Cammarata 9ac624d2c9 Fix mock DictDataLoader _get_file_contents to match real code 9 years ago
James Cammarata fe41f109a9 Merge branch 'v2_final' into devel_switch_v2 9 years ago
James Cammarata 4bc7703db3 Fixing some small bugs related to integration tests (v2) 9 years ago
James Cammarata 0828028c71 Fixing unit test for included file changes 9 years ago
James Cammarata 2bad888f28 Merge branch 'v2_final' into devel_switch_v2
Conflicts:
	lib/ansible/inventory/__init__.py
	lib/ansible/modules/core
	lib/ansible/utils/__init__.py
	lib/ansible/utils/module_docs.py
9 years ago
James Cammarata e59d4f3b51 More module_utils/basic.py unit tests for v2 9 years ago
James Cammarata 339a02c384 Started reworking module_utils/basic unit tests (v2) 9 years ago
James Cammarata d4a31e8d26 Adding unit tests for TaskExecutor (v2) 9 years ago
Serge van Ginderachter b92d70c5b6 tests files extensions in group/host_vars dir
only files with extensions as per
C.YAML_FILENAME_EXTENSIONS should be parsed
9 years ago
James Cammarata 838ff32001 Fix unit test for conn_info (v2)
The default user expected in the connection information is the current
user, not root
9 years ago
James Cammarata ecd5eb902d Adding unit tests for ConnectionInformation (v2) 9 years ago
James Cammarata 9921a1d2be Unit tests for base strategy class (v2) 9 years ago
James Cammarata 21fa385ce7 Reorganizing plugin unit tests and adding start of strategy tests (v2) 9 years ago
James Cammarata a960fcd569 Adding module_utils tests from v1 to v2 9 years ago
James Cammarata 398b1d3e60 Cleaning up template test syntax a bit 9 years ago
James Cammarata 9aa8676bdd More template unit tests for v2 9 years ago
James Cammarata 23cd3294d0 Starting to add v2 tests for template 9 years ago
James Cammarata 48d62fd934 Cleaning up VariableManager tests (v2) 9 years ago
James Cammarata a0509cda1e Fix test_role unit tests to use unique role names to avoid role caching errors 9 years ago
James Cammarata 1ca8cb8553 Fixing up v2 unit tests 9 years ago
Toshio Kuratomi f9f8af06fc Change asserts to assertIsInstance for better error messages 10 years ago
Matt Martz a0fc8bb0bd Testing additions and fixes
* Fix import pathing for units.mock
* Add some additional requirements
* Use compileall to test compatiblity with different python versions
10 years ago
James Cammarata ce3ef7f4c1 Making the switch to v2 10 years ago
Jesse Rusak 652cd6cd5e Fix --force-handlers, and allow it in plays and ansible.cfg
The --force-handlers command line argument was not correctly running
handlers on hosts which had tasks that later failed. This corrects that,
and also allows you to specify force_handlers in ansible.cfg or in a
play.
10 years ago
James Laska 60acdee0dc Enable assert_raises_regexp on py26 10 years ago
Toshio Kuratomi f05cda6ffc Comma is also dependent on position within the hash 10 years ago
Brian Coca 74bf59082d fixed and reintroduced syncronize test, fakerunner object needed become_method to be it's default 'sudo' 10 years ago
Toshio Kuratomi 644e50fe34 Hash randomization makes one of the heuristic_log_sanitize checks not work.
Nothing we can do, when it sanitizes ssh_urls it's simply overzealous.
10 years ago
Brian Coca 587ab17f10 fixes password error detection for ssh connection plugin
removes sycnronize test that does not work with current sudo setup
Fixes #10434
10 years ago