コード例 #1
0
    def test_sw2(self):
        id = 'ansible-ws-unittest'

        # KILL
        parameters = {
            'id': id,
        }
        request = tests.get_sw2_request('SSHAgentKill', parameters)
        #         pprint.pprint(request)
        sw2 = ScriptWebServiceWrapper(request, self.config)
        response = sw2.get_result()
        #         pprint.pprint(response)
        self.assertEqual(response['results']['keys'], None)
        self.assertEqual(response['results']['action'], 'kill')
        self.assertEqual(response['results']['rc'], 0)

        # INFO
        parameters = {
            'id': id,
        }
        request = tests.get_sw2_request('SSHAgent', parameters)
        #         pprint.pprint(request)
        sw2 = ScriptWebServiceWrapper(request, self.config)
        response = sw2.get_result()
        #         pprint.pprint(response)
        self.assertEqual(response['results']['keys'], [])
        self.assertEqual(response['results']['action'], 'init')

        # ADD
        parameters = {
            'id': id,
            'private_key': self.key1,
            'passphrase': 'key1',
        }
        request = tests.get_sw2_request('SSHAgentAdd', parameters)
        #         pprint.pprint(request)
        sw2 = ScriptWebServiceWrapper(request, self.config)
        response = sw2.get_result()
        #         pprint.pprint(response)
        self.assertEqual(response['results']['action'], 'add')
        self.assertTrue(response['results']['keys'][0].startswith('ssh-rsa '))

        # KILL
        parameters = {
            'id': id,
        }
        request = tests.get_sw2_request('SSHAgentKill', parameters)
        #         pprint.pprint(request)
        sw2 = ScriptWebServiceWrapper(request, self.config)
        response = sw2.get_result()
        #         pprint.pprint(response)
        self.assertEqual(response['results']['keys'], None)
        self.assertEqual(response['results']['action'], 'kill')
        self.assertEqual(response['results']['rc'], 0)
コード例 #2
0
ファイル: test_groups.py プロジェクト: vengaar/ansible-ws
 def test_groups_list(self):
     parameters = {
         'pattern': '(database_app1_dev|database_app2_prod)',
         'groups_selection': 'yes',
         'sources': self.sources
     }
     request = tests.get_sw2_request(self.query, parameters)
     #         pprint.pprint(request)
     sw2 = ScriptWebServiceWrapper(request, self.config)
     response = sw2.get_result()
     #         pprint.pprint(response)
     values = [option['value'] for option in response['results']]
     expected = [
         'database_app1_dev',
         'server_dev_x1',
         'server_dev_x2',
         'database_app2_prod',
         'db_prod_21',
         'db_prod_22',
         'db_prod_23',
     ]
     #         pprint.pprint(values)
     self.assertEqual(values, expected)
     self.assertEqual(response['results'][0]['disabled'], False)
     self.assertEqual(response['results'][3]['disabled'], False)
コード例 #3
0
ファイル: test_tasks.py プロジェクト: vengaar/ansible-ws
    def test_tasks(self):
        playbook = os.path.expanduser(
            '~/ansible-ws/tests/data/playbooks/tags.yml')
        parameters = {
            'playbook': playbook,
        }
        request = tests.get_sw2_request('tasks', parameters, cache='refresh')
        #         pprint.pprint(request)
        sw2 = ScriptWebServiceWrapper(request, self.config)
        response = sw2.get_result()
        #         pprint.pprint(response)
        expected = [{
            'name': value,
            'value': value
        } for value in [
            'task11',
            'task12 with long name',
            'task13',
            'debug',
            'task21',
            'task22',
        ]]
        self.assertEqual(response['results'], expected)

        ### test with cache
        request['sw2'].pop('cache')
        sw2 = ScriptWebServiceWrapper(request, self.config)
        response = sw2.get_result()
        self.assertEqual(response['results'], expected)
コード例 #4
0
ファイル: test_sw2.py プロジェクト: vengaar/ansible-ws
 def test_demo(self):
     parameters = {'demo1': 'test', 'demo2': ['foo', 'bar']}
     request = tests.get_sw2_request('demo', parameters)
     #         pprint.pprint(request)
     sw2 = ScriptWebServiceWrapper(request, self.config)
     response = sw2.get_result()
     #         pprint.pprint(response)
     self.assertEqual(response['results'][3]['name'], 'test')
     self.assertEqual(response['results'][4]['name'], 'foo')
コード例 #5
0
ファイル: test_groups.py プロジェクト: vengaar/ansible-ws
 def test_default(self):
     parameters = {
         'pattern': 'all',
     }
     request = tests.get_sw2_request(self.query, parameters)
     #         pprint.pprint(request)
     sw2 = ScriptWebServiceWrapper(request, self.config)
     response = sw2.get_result()
     #         pprint.pprint(response)
     self.assertIsInstance(response['results'], list)
コード例 #6
0
ファイル: test_runs.py プロジェクト: vengaar/ansible-ws
 def test_search_basic(self):
     parameters = {
         'from': 'January 1, 2019',
     }
     request = tests.get_sw2_request('runs', parameters)
     #         pprint.pprint(request)
     sw2 = ScriptWebServiceWrapper(request, self.ansible_ws_config)
     response = sw2.get_result()
     #         pprint.pprint(response)
     #         print(len(response['results']))
     self.assertEqual(len(response['results']), 6)
コード例 #7
0
ファイル: test_groupvars.py プロジェクト: vengaar/ansible-ws
    def test_default(self):
        parameters = {
            'group': 'foo',
            'key': 'foo.barr',
        }
        request = tests.get_sw2_request(self.query, parameters)
#         pprint.pprint(request)
        sw2 = ScriptWebServiceWrapper(request, self.config)
        response = sw2.get_result()
#         pprint.pprint(response)
        expected = []
        self.assertEqual(response['results'], expected)
コード例 #8
0
ファイル: test_tags.py プロジェクト: vengaar/ansible-ws
 def test_no_tags(self):
     playbook = os.path.expanduser(
         '~/ansible-ws/tests/data/playbooks/notags.yml')
     parameters = {
         'playbook': playbook,
     }
     request = tests.get_sw2_request('tags', parameters)
     #         pprint.pprint(request)
     sw2 = ScriptWebServiceWrapper(request, self.config)
     response = sw2.get_result()
     #         pprint.pprint(response)
     expected = []
     self.assertEqual(response['results'], expected)
コード例 #9
0
ファイル: test_runs.py プロジェクト: vengaar/ansible-ws
 def test_search_state(self):
     parameters = {'from': 'January 1, 2019', 'states': 'failed'}
     request = tests.get_sw2_request('runs', parameters)
     #         pprint.pprint(request)
     sw2 = ScriptWebServiceWrapper(request, self.ansible_ws_config)
     response = sw2.get_result()
     #         pprint.pprint(response)
     #         print(len(response['results']))
     self.assertEqual(response['results'][0]['runid'],
                      'f14529a2-cd83-4d2c-b885-a6184b83f7bc')
     self.assertEqual(response['results'][1]['runid'],
                      'f61aef56-9700-48a8-ab1e-f049df76ec0b')
     self.assertEqual(len(response['results']), 2)
コード例 #10
0
 def test_grapher(self):
     grapher_output = '/tmp'
     self.config.config['grapher']['output'] = grapher_output
     expected_file = '/tmp/db_prod_11.png'
     if os.path.isfile(expected_file):
         os.remove(expected_file)
     parameters = {'host': 'db_prod_11', 'inventory': self.inventory}
     request = tests.get_sw2_request(self.query, parameters)
     #         pprint.pprint(request)
     sw2 = ScriptWebServiceWrapper(request, self.config)
     response = sw2.get_result()
     #         pprint.pprint(response)
     self.assertTrue(os.path.isfile(expected_file))
     os.remove(expected_file)
コード例 #11
0
    def test_sw2(self):
        parameters = {
            'cmdline': f'ansible-playbook  {self.playbook} -v',
            'playbook': self.playbook,
        }
        request = tests.get_sw2_request('launch', parameters)
#         pprint.pprint(request)
        sw2 = ScriptWebServiceWrapper(request, self.config)
        response = sw2.get_result()
#         pprint.pprint(response)
        results = response['results']
#         pprint.pprint(results)
        self.assertIsNone(results['return_code'])
        self.assertEqual(results['state'], PlaybookContext.STATE_RUNNING)
        self.assertEqual(results['status'], PlaybookContext.STATUS_READY)
        runid = results['runid']

        parameters = {
            'runid': runid
        }
        request = tests.get_sw2_request('run', parameters)
#         pprint.pprint(request)
        sw2 = ScriptWebServiceWrapper(request, self.config)
        response = sw2.get_result()
#         pprint.pprint(response)
        status = response['results']['status']
#         pprint.pprint(status)
        self.assertEqual(status['runid'], runid)
        while status['status'] != PlaybookContext.STATUS_FINISHED:
            time.sleep(5)
            sw2 = ScriptWebServiceWrapper(request, self.config)
            response = sw2.get_result()
#             pprint.pprint(response)
            status = response['results']['status']
        self.assertEqual(status['return_code'], 0)
        self.assertEqual(status['state'], PlaybookContext.STATE_SUCCEEDED)
        self.assertEqual(status['status'], PlaybookContext.STATUS_FINISHED)
コード例 #12
0
ファイル: test_groupvars.py プロジェクト: vengaar/ansible-ws
    def test_dict(self):
        parameters = {
            'group': 'database_app1_prod',
            'key': 'countries.dict',
            'inventories': self.inventories
        }
        request = tests.get_sw2_request(self.query, parameters)
#         pprint.pprint(request)
        sw2 = ScriptWebServiceWrapper(request, self.config)
        response = sw2.get_result()
#         pprint.pprint(response)
        expected = [
            {'name': value, 'value': value}
            for value in ['es', 'fr', 'it']
        ]
        self.assertEqual(response['results'], expected)