예제 #1
0
    def setUp(self):
        super(TestOnyxVxlanModule, self).setUp()
        self.mock_get_vxlan_config = patch.object(
            onyx_vxlan.OnyxVxlanModule, "_show_vxlan_config")
        self.get_vxlan_config = self.mock_get_vxlan_config.start()

        self.mock_load_config = patch(
            'ansible_collections.ansible.misc.plugins.module_utils.network.onyx.onyx.load_config')
        self.load_config = self.mock_load_config.start()

        self.mock_get_nve_detail = patch.object(
            onyx_vxlan.OnyxVxlanModule, "_show_nve_detail")
        self.get_nve_detail = self.mock_get_nve_detail.start()
    def setUp(self):
        super(TestOnyxTrafficClassModule, self).setUp()
        self.mock_get_congestion_control_config = patch.object(
            onyx_traffic_class.OnyxTrafficClassModule, "_show_interface_congestion_control")
        self.get_congestion_control_config = self.mock_get_congestion_control_config.start()

        self.mock_load_config = patch(
            'ansible_collections.ansible.misc.plugins.module_utils.network.onyx.onyx.load_config')
        self.load_config = self.mock_load_config.start()

        self.mock_get_dcb_config = patch.object(
            onyx_traffic_class.OnyxTrafficClassModule, "_show_interface_dcb_ets")
        self.get_dcb_config = self.mock_get_dcb_config.start()
예제 #3
0
    def setUp(self):
        super(TestOnyxLinkaggModule, self).setUp()
        self.mock_get_config = patch.object(
            onyx_linkagg.OnyxLinkAggModule,
            "_get_port_channels")
        self.get_config = self.mock_get_config.start()

        self.mock_load_config = patch(
            'ansible_collections.ansible.misc.plugins.module_utils.network.onyx.onyx.load_config')
        self.load_config = self.mock_load_config.start()
        self.mock_get_version = patch.object(
            onyx_linkagg.OnyxLinkAggModule, "_get_os_version")
        self.get_version = self.mock_get_version.start()
예제 #4
0
    def setUp(self):
        super(TestOnyxMagpModule, self).setUp()
        self.mock_get_config = patch.object(onyx_magp.OnyxMagpModule,
                                            "_get_magp_config")
        self.get_config = self.mock_get_config.start()

        self.mock_load_config = patch(
            'ansible_collections.ansible.misc.plugins.module_utils.network.onyx.onyx.load_config'
        )
        self.load_config = self.mock_load_config.start()

        self.mock_get_version = patch.object(onyx_magp.OnyxMagpModule,
                                             "_get_os_version")
        self.get_version = self.mock_get_version.start()
예제 #5
0
    def setUp(self):
        super(TestOnyxMlagVipModule, self).setUp()
        self._mlag_enabled = True
        self.mock_show_mlag = patch.object(onyx_mlag_vip.OnyxMLagVipModule,
                                           "_show_mlag")
        self.show_mlag = self.mock_show_mlag.start()
        self.mock_show_mlag_vip = patch.object(onyx_mlag_vip.OnyxMLagVipModule,
                                               "_show_mlag_vip")
        self.show_mlag_vip = self.mock_show_mlag_vip.start()

        self.mock_load_config = patch(
            'ansible_collections.ansible.misc.plugins.module_utils.network.onyx.onyx.load_config'
        )
        self.load_config = self.mock_load_config.start()
예제 #6
0
    def setUp(self):
        super(TestOnyxInterfaceModule, self).setUp()
        self.mock_get_config = patch.object(
            onyx_l2_interface.OnyxL2InterfaceModule, "_get_switchport_config")
        self.get_config = self.mock_get_config.start()

        self.mock_load_config = patch(
            'ansible_collections.ansible.misc.plugins.module_utils.network.onyx.onyx.load_config'
        )
        self.load_config = self.mock_load_config.start()

        self.mock_get_version = patch.object(
            onyx_l2_interface.OnyxL2InterfaceModule, "_get_os_version")
        self.get_version = self.mock_get_version.start()
예제 #7
0
    def setUp(self):
        super(TestOnyxOspfModule, self).setUp()
        self._ospf_exists = True
        self.mock_get_config = patch.object(onyx_ospf.OnyxOspfModule,
                                            "_get_ospf_config")
        self.get_config = self.mock_get_config.start()

        self.mock_get_interfaces_config = patch.object(
            onyx_ospf.OnyxOspfModule, "_get_ospf_interfaces_config")
        self.get_interfaces_config = self.mock_get_interfaces_config.start()

        self.mock_load_config = patch(
            'ansible_collections.ansible.misc.plugins.module_utils.network.onyx.onyx.load_config'
        )
        self.load_config = self.mock_load_config.start()
예제 #8
0
    def test_successful_message_with_notify(self):
        """Test failure message"""
        set_module_args({
            'subscription': 'test',
            'token': 'abc',
            'room': 'test',
            'msg': 'test',
            'notify': 'bell'
        })

        with patch.object(campfire, "fetch_url") as fetch_url_mock:
            fetch_url_mock.return_value = (None, {"status": 200})
            with self.assertRaises(AnsibleExitJson):
                self.module.main()

            assert fetch_url_mock.call_count == 2
            notify_call = fetch_url_mock.mock_calls[0]
            url = notify_call[1][1]
            data = notify_call[2]['data']

            assert url == 'https://test.campfirenow.com/room/test/speak.xml'
            assert data == '<message><type>SoundMessage</type><body>bell</body></message>'

            message_call = fetch_url_mock.mock_calls[1]
            url = message_call[1][1]
            data = message_call[2]['data']

            assert url == 'https://test.campfirenow.com/room/test/speak.xml'
            assert data == '<message><body>test</body></message>'
예제 #9
0
    def setUp(self):
        super(TestOnyxBgpModule, self).setUp()
        self.mock_get_config = patch.object(
            onyx_bgp.OnyxBgpModule, "_get_bgp_summary")
        self.get_config = self.mock_get_config.start()

        self.mock_load_config = patch(
            'ansible_collections.ansible.misc.plugins.module_utils.network.onyx.onyx.load_config')
        self.load_config = self.mock_load_config.start()
예제 #10
0
 def setUp(self):
     """Setup."""
     super(TestIcinga2Feature, self).setUp()
     self.module = icinga2_feature
     self.mock_get_bin_path = patch.object(basic.AnsibleModule,
                                           'get_bin_path', get_bin_path)
     self.mock_get_bin_path.start()
     self.addCleanup(self.mock_get_bin_path.stop
                     )  # ensure that the patching is 'undone'
예제 #11
0
    def test_content_written(self):

        with patch.object(builtins, 'open', mock_open()) as m:
            password._write_password_file(b'/this/is/a/test/caf\xc3\xa9',
                                          u'Testing Café')

            m.assert_called_once_with(b'/this/is/a/test/caf\xc3\xa9', 'wb')
            m().write.assert_called_once_with(
                u'Testing Café\n'.encode('utf-8'))
예제 #12
0
    def setUp(self):
        super(TestOnyxQosModule, self).setUp()
        self.mock_get_if_qos_config = patch.object(
            onyx_qos.OnyxQosModule, "_show_interface_qos")
        self.get_if_qos_config = self.mock_get_if_qos_config.start()

        self.mock_load_config = patch(
            'ansible_collections.ansible.misc.plugins.module_utils.network.onyx.onyx.load_config')
        self.load_config = self.mock_load_config.start()
예제 #13
0
    def setUp(self):
        self.enabled = False
        super(TestOnyxSysLogRemoteModule, self).setUp()
        self.mock_get_config = patch.object(
            onyx_syslog_remote.OnyxSyslogRemoteModule, "show_logging")
        self.get_config = self.mock_get_config.start()

        self.mock_load_config = patch(
            'ansible_collections.ansible.misc.plugins.module_utils.network.onyx.onyx.load_config')
        self.load_config = self.mock_load_config.start()
예제 #14
0
    def setUp(self):
        self.enabled = False
        super(TestOnyxBFDModule, self).setUp()
        self.mock_get_config = patch.object(
            onyx_bfd.OnyxBFDModule, "_show_bfd_config")
        self.get_config = self.mock_get_config.start()

        self.mock_load_config = patch(
            'ansible_collections.ansible.misc.plugins.module_utils.network.onyx.onyx.load_config')
        self.load_config = self.mock_load_config.start()
예제 #15
0
    def setUp(self):
        super(TestOnyxBufferPoolModule, self).setUp()
        self.mock_get_buffer_pool_config = patch.object(
            onyx_buffer_pool.OnyxBufferPoolModule, "_show_traffic_pool")
        self.get_buffer_pool_config = self.mock_get_buffer_pool_config.start()

        self.mock_load_config = patch(
            'ansible_collections.ansible.misc.plugins.module_utils.network.onyx.onyx.load_config'
        )
        self.load_config = self.mock_load_config.start()
예제 #16
0
    def setUp(self):
        super(TestOnyxInterfaceModule, self).setUp()
        self.mock_get_config = patch.object(onyx_lldp.OnyxLldpModule,
                                            "_get_lldp_config")
        self.get_config = self.mock_get_config.start()

        self.mock_load_config = patch(
            'ansible_collections.ansible.misc.plugins.module_utils.network.onyx.onyx.load_config'
        )
        self.load_config = self.mock_load_config.start()
예제 #17
0
    def test_disable_feature(self):
        """Check that result is changed."""
        set_module_args({'name': 'api', 'state': 'absent'})
        with patch.object(basic.AnsibleModule, 'run_command') as run_command:
            run_command.return_value = 0, '', ''  # successful execution, no output
            with self.assertRaises(AnsibleExitJson) as result:
                icinga2_feature.main()
                self.assertTrue(result.exception.args[0]['changed'])

        self.assertEqual(run_command.call_count, 2)
        self.assertEqual(run_command.call_args[0][0][-1], 'api')
예제 #18
0
    def setUp(self):
        super(TestOnyxMlagIplModule, self).setUp()
        self._mlag_enabled = True
        self.mock_get_config = patch.object(onyx_mlag_ipl.OnyxMlagIplModule,
                                            "_show_mlag_data")
        self.get_config = self.mock_get_config.start()

        self.mock_load_config = patch(
            'ansible_collections.ansible.misc.plugins.module_utils.network.onyx.onyx.load_config'
        )
        self.load_config = self.mock_load_config.start()
    def setUp(self):
        self.enabled = False
        super(TestOnyxNtpServersPeersModule, self).setUp()
        self.mock_get_config = patch.object(
            onyx_ntp_servers_peers.OnyxNTPServersPeersModule,
            "_show_peers_servers_config")
        self.get_config = self.mock_get_config.start()

        self.mock_load_config = patch(
            'ansible_collections.ansible.misc.plugins.module_utils.network.onyx.onyx.load_config'
        )
        self.load_config = self.mock_load_config.start()
예제 #20
0
    def test_enable_feature_with_check_mode(self):
        """Check that result is changed in check mode."""
        set_module_args({
            'name': 'api',
            '_ansible_check_mode': True,
        })
        with patch.object(basic.AnsibleModule, 'run_command') as run_command:
            run_command.return_value = 0, '', ''  # successful execution, no output
            with self.assertRaises(AnsibleExitJson) as result:
                icinga2_feature.main()
                self.assertTrue(result.exception.args[0]['changed'])

        self.assertEqual(run_command.call_count, 1)
예제 #21
0
    def test_failure_message(self):
        """Test failure message"""
        set_module_args({
            'subscription': 'test',
            'token': 'abc',
            'room': 'test',
            'msg': 'test'
        })

        with patch.object(campfire, "fetch_url") as fetch_url_mock:
            fetch_url_mock.return_value = (None, {"status": 403})
            with self.assertRaises(AnsibleFailJson):
                self.module.main()
예제 #22
0
 def test_lock_been_held(self, mock_sleep):
     # pretend the lock file is here
     password.os.path.exists = lambda x: True
     try:
         with patch.object(
                 builtins, 'open',
                 mock_open(read_data=b'hunter42 salt=87654321\n')) as m:
             # should timeout here
             results = self.password_lookup.run(
                 [u'/path/to/somewhere chars=anything'], None)
             self.fail("Lookup didn't timeout when lock already been held")
     except AnsibleError:
         pass
예제 #23
0
    def test_password_already_created_no_encrypt(self, mock_get_paths,
                                                 mock_write_file):
        mock_get_paths.return_value = ['/path/one', '/path/two', '/path/three']
        password.os.path.exists = lambda x: x == to_bytes('/path/to/somewhere')

        with patch.object(
                builtins, 'open',
                mock_open(read_data=b'hunter42 salt=87654321\n')) as m:
            results = self.password_lookup.run(
                [u'/path/to/somewhere chars=anything'], None)

        for result in results:
            self.assertEqual(result, u'hunter42')
예제 #24
0
    def setUp(self):
        self.enabled = False
        super(TestOnyxIgmpVlan, self).setUp()
        self.mock_get_igmp_config = patch.object(
            onyx_igmp_vlan.OnyxIgmpVlanModule, "_show_igmp_vlan")
        self.get_igmp_config = self.mock_get_igmp_config.start()

        self.mock_load_config = patch(
            'ansible_collections.ansible.misc.plugins.module_utils.network.onyx.onyx.load_config'
        )
        self.load_config = self.mock_load_config.start()

        self.mock_get_igmp_guerier_config = patch.object(
            onyx_igmp_vlan.OnyxIgmpVlanModule, "_show_igmp_querier_config")
        self.get_igmp_guerier_config = self.mock_get_igmp_guerier_config.start(
        )

        self.mock_get_igmp_static_groups_config = patch.object(
            onyx_igmp_vlan.OnyxIgmpVlanModule,
            "_show_igmp_snooping_groups_config")
        self.get_igmp_static_groups_config = self.mock_get_igmp_static_groups_config.start(
        )
    def test_dont_create_same_value(self, *args):
        with patch.object(self.module, 'create_known_host') as create_known_host_mock:
            with self.assertRaises(AnsibleExitJson) as exec_info:
                set_module_args({
                    'client_id': 'ABC',
                    'client_secret': 'XXX',
                    'username': '******',
                    'repository': 'repo',
                    'name': 'bitbucket.org',
                    'state': 'present',
                })
                self.module.main()

            self.assertEqual(create_known_host_mock.call_count, 0)
            self.assertEqual(exec_info.exception.args[0]['changed'], False)
예제 #26
0
    def test_lock_not_been_held(self):
        # pretend now there is password file but no lock
        password.os.path.exists = lambda x: x == to_bytes('/path/to/somewhere')
        try:
            with patch.object(
                    builtins, 'open',
                    mock_open(read_data=b'hunter42 salt=87654321\n')) as m:
                # should not timeout here
                results = self.password_lookup.run(
                    [u'/path/to/somewhere chars=anything'], None)
        except AnsibleError:
            self.fail('Lookup timeouts when lock is free')

        for result in results:
            self.assertEqual(result, u'hunter42')
예제 #27
0
    def test_delete_variable(self, *args):
        with patch.object(self.module, 'delete_pipeline_variable') as delete_pipeline_variable_mock:
            with self.assertRaises(AnsibleExitJson) as exec_info:
                set_module_args({
                    'client_id': 'ABC',
                    'client_secret': 'XXX',
                    'username': '******',
                    'repository': 'repo',
                    'name': 'PIPELINE_VAR_NAME',
                    'state': 'absent',
                })
                self.module.main()

            self.assertEqual(delete_pipeline_variable_mock.call_count, 1)
            self.assertEqual(exec_info.exception.args[0]['changed'], True)
예제 #28
0
    def test_delete_absent_keys(self, *args):
        with patch.object(self.module,
                          'delete_ssh_key_pair') as delete_ssh_key_pair_mock:
            with self.assertRaises(AnsibleExitJson) as exec_info:
                set_module_args({
                    'client_id': 'ABC',
                    'client_secret': 'XXX',
                    'username': '******',
                    'repository': 'repo',
                    'state': 'absent',
                })
                self.module.main()

            self.assertEqual(delete_ssh_key_pair_mock.call_count, 0)
            self.assertEqual(exec_info.exception.args[0]['changed'], False)
    def test_create_known_host_with_key(self, *args):
        with patch.object(self.module, 'get_host_key') as get_host_key_mock:
            with self.assertRaises(AnsibleExitJson) as exec_info:
                set_module_args({
                    'client_id': 'ABC',
                    'client_secret': 'XXX',
                    'username': '******',
                    'repository': 'repo',
                    'name': 'bitbucket.org',
                    'key': 'ssh-rsa public',
                    'state': 'present',
                })
                self.module.main()

            self.assertEqual(get_host_key_mock.call_count, 0)
            self.assertEqual(exec_info.exception.args[0]['changed'], True)
예제 #30
0
    def test_password_already_created_encrypt(self, mock_get_paths,
                                              mock_write_file):
        mock_get_paths.return_value = ['/path/one', '/path/two', '/path/three']
        password.os.path.exists = lambda x: x == to_bytes('/path/to/somewhere')

        with patch.object(
                builtins, 'open',
                mock_open(read_data=b'hunter42 salt=87654321\n')) as m:
            results = self.password_lookup.run(
                [u'/path/to/somewhere chars=anything encrypt=pbkdf2_sha256'],
                None)
        for result in results:
            self.assertEqual(
                result,
                u'$pbkdf2-sha256$20000$ODc2NTQzMjE$Uikde0cv0BKaRaAXMrUQB.zvG4GmnjClwjghwIRf2gU'
            )