def test_rollback_all_invalid(self, mock_runner, mock_generate,
                                  mock_logger):
        """CLI - Lambda Rollback all invalid"""
        options = MockOptions(None, ['all'])

        # Versions $LATEST and 1 cannot be rolled back.
        self.alert_config['current_version'] = 1
        rollback.rollback(options, self.config)

        fmt = '%s cannot be rolled back from version %s'
        mock_logger.assert_has_calls([
            call.warn(fmt, 'alert_merger', '$LATEST'),
            call.warn(fmt, 'alert_processor', '1'),
            call.warn(fmt, 'duo_admin_collector_corp', '$LATEST'),
            call.warn(fmt, 'box_collector_corp', '$LATEST'),
            call.warn(fmt, 'athena_partition_refresh', '$LATEST'),
            call.warn(fmt, 'rule_processor_prod', '$LATEST'),
            call.warn(fmt, 'rule_processor_corp', '$LATEST'),
            call.warn(fmt, 'threat_intel_downloader_config', '$LATEST')
        ],
                                     any_order=True)

        # We should have returned early - no Terraform actions necessary
        mock_generate.assert_not_called()
        mock_runner.assert_not_called()
Exemple #2
0
 def test_device_re_name_is_old_facts(self, mock_warn):
     localdev = Device(host='1.1.1.1', user='******', password='******',
                       fact_style='old', gather_facts=False)
     mock_warn.assert_has_calls([call.warn('fact-style old will be removed '
                                           'in a future release.',
                                           RuntimeWarning)])
     self.assertEqual(localdev.re_name, None)
Exemple #3
0
 def test_rpcmeta_exec_rpc_format_json_lt_14_2(self, mock_warn):
     self.dev._conn.rpc = MagicMock(side_effect=self._mock_manager)
     self.dev._facts['version_info'] = version_info('13.1X46-D15.3')
     self.rpc.get_system_users_information(dict(format='json'))
     mock_warn.assert_has_calls(
         call.warn('Native JSON support is only from 14.2 onwards',
                   RuntimeWarning))
 def test_device_re_name_is_old_facts(self, mock_warn):
     localdev = Device(host='1.1.1.1', user='******', password='******',
                       fact_style='old', gather_facts=False)
     mock_warn.assert_has_calls([call.warn('fact-style old will be removed '
                                           'in a future release.',
                                           RuntimeWarning)])
     self.assertEqual(localdev.re_name, None)
Exemple #5
0
 def test_rpcmeta_exec_rpc_format_json_lt_14_2(self, mock_warn):
     self.dev._conn.rpc = MagicMock(side_effect=self._mock_manager)
     self.dev.facts._cache["version_info"] = version_info("13.1X46-D15.3")
     self.rpc.get_system_users_information(dict(format="json"))
     mock_warn.assert_has_calls([
         call.warn("Native JSON support is only from 14.2 onwards",
                   RuntimeWarning)
     ])
Exemple #6
0
 def test_factcache_refresh_warnings_on_failure(self,
                                                mock_warn,
                                                mock_device_warn):
     # Refresh all facts with warnings on failure
     self.dev.facts._refresh(warnings_on_failure=True)
     mock_warn.assert_has_calls([call.warn(
         'Facts gathering is incomplete. To know the reason call '
         '"dev.facts_refresh(exception_on_failure=True)"',
                                 RuntimeWarning)])
 def test_factcache_refresh_warnings_on_failure(self,
                                                mock_warn,
                                                mock_device_warn):
     # Refresh all facts with warnings on failure
     self.dev.facts._refresh(warnings_on_failure=True)
     mock_warn.assert_has_calls([call.warn(
         'Facts gathering is incomplete. To know the reason call '
         '"dev.facts_refresh(exception_on_failure=True)"',
                                 RuntimeWarning)])
Exemple #8
0
 def test_telnet_old_fact_warning(self, mock_warn):
     self.dev = Console(host='1.1.1.1',
                        user='******',
                        password='******',
                        mode='Telnet',
                        fact_style='old')
     mock_warn.assert_has_calls([
         call.warn('fact-style old will be removed in a future release.',
                   RuntimeWarning)
     ])
Exemple #9
0
 def test_telnet_old_fact_warning(self, mock_warn):
     self.dev = Console(
         host='1.1.1.1',
         user='******',
         password='******',
         mode='Telnet',
         fact_style='old')
     mock_warn.assert_has_calls([call.warn(
         'fact-style old will be removed in a future release.',
         RuntimeWarning)])
    def test_cannot_load_classes_value_error(self, get_class_mock, log_mock):
        get_class_mock.side_effect = ValueError
        classes = load_classes(default=['blah.models.blah.Test'])

        expect(classes).to_length(0)
        expect(log_mock.mock_calls).to_include(
            call.warn(
                'Invalid class name [%s]. Will be ignored.',
                'blah.models.blah.Test'
            )
        )
    def test_cannot_load_classes_attr_error(self, get_class_mock, log_mock):
        get_class_mock.side_effect = AttributeError
        classes = load_classes(default=['blah.models.blah.Test'])

        expect(classes).to_length(0)
        expect(log_mock.mock_calls).to_include(
            call.warn(
                'Class [%s] not found. Will be ignored.',
                'blah.models.blah.Test'
            )
        )
Exemple #12
0
def test_connection_passed_warning_raised():
    with patch('pymongo.MongoClient', return_value=MagicMock(), autospec=True), \
         patch('arctic.arctic.mongo_retry', side_effect=lambda x: x, autospec=True), \
         patch('arctic.arctic.get_auth', autospec=True), \
         patch('arctic.arctic.logger') as lg:
        magic_mock = MagicMock(nodes={("host", "port")})
        store = Arctic(magic_mock, ssl=True)
        # Increment _pid to simulate forking the process
        store._pid += 1
        _ = store._conn
        assert lg.mock_calls[0] == call.warn('Forking process. Arctic was passed a pymongo connection during init, '
                                             'the new pymongo connection may have different parameters.')
Exemple #13
0
def test_connection_passed_warning_raised():
    with patch('pymongo.MongoClient', return_value=MagicMock(), autospec=True), \
         patch('arctic.arctic.mongo_retry', side_effect=lambda x: x, autospec=True), \
         patch('arctic.arctic.get_auth', autospec=True), \
         patch('arctic.arctic.logger') as lg:
        magic_mock = MagicMock(nodes={("host", "port")})
        store = Arctic(magic_mock, ssl=True)
        # Increment _pid to simulate forking the process
        store._pid += 1
        _ = store._conn
        assert lg.mock_calls[0] == call.warn(
            'Forking process. Arctic was passed a pymongo connection during init, '
            'the new pymongo connection may have different parameters.')
Exemple #14
0
 def test_device_re_name_is_old_facts(self, mock_warn):
     localdev = Device(
         host="1.1.1.1",
         user="******",
         password="******",
         fact_style="old",
         gather_facts=False,
     )
     mock_warn.assert_has_calls([
         call.warn(
             "fact-style old will be removed "
             "in a future release.",
             RuntimeWarning,
         )
     ])
     self.assertEqual(localdev.re_name, None)
Exemple #15
0
 def test_telnet_old_fact_warning(self, mock_warn):
     self.dev = Console(
         host="1.1.1.1",
         user="******",
         password="******",
         mode="Telnet",
         fact_style="old",
     )
     mock_warn.assert_has_calls(
         [
             call.warn(
                 "fact-style old will be removed in a future release.",
                 RuntimeWarning,
             )
         ]
     )
 def test_factcache_nonmatching_old_and_new_fact(self, mock_warn):
     # Set fact style to 'both'
     self.dev._fact_style = 'both'
     # Create a callback for the foo fact.
     self.dev.facts._callbacks['foo'] = get_foo_fact
     # Cache the new-style foo fact
     self.dev.facts._cache['foo'] = 'foo'
     # Set the old-style foo fact to a different value
     self.dev._ofacts['foo'] = 'bar'
     # Now, trying to access the foo fact should cause a
     # RunTimeWarning because the values of the new and old-style facts
     # do not match
     foo = self.dev.facts['foo']
     mock_warn.assert_has_calls([call.warn(
         'New and old-style facts do not match for the foo fact.\n'
         '    New-style value: foo\n    Old-style value: bar\n',
                                 RuntimeWarning)])
Exemple #17
0
def test_missing_host_key_ignore(tempdir, sshclient):
    from ploy.common import SSHKeyFingerprintIgnore
    from ploy.plain import ServerHostKeyPolicy
    known_hosts = tempdir['known_hosts'].path
    sshclient._host_keys_filename = known_hosts
    shkp = ServerHostKeyPolicy(lambda: [SSHKeyFingerprintIgnore()])
    key = MagicMock()
    key.asbytes.return_value = b'foo'
    key.get_name.return_value = 'ssh-rsa'
    with patch('ploy.common.log') as LogMock:
        shkp.missing_host_key(sshclient, 'localhost', key)
    assert sshclient.mock_calls == [
        call.get_host_keys(),
        call.get_host_keys().add('localhost', 'ssh-rsa', key),
        call.save_host_keys(known_hosts)]
    assert LogMock.method_calls == [
        call.warn(
            'Fingerprint verification disabled!\n'
            'Got fingerprint ac:bd:18:db:4c:c2:f8:5c:ed:ef:65:4f:cc:c4:a4:d8.')]
Exemple #18
0
    def test_update_limits_from_api_invalid_region(self):
        def se_get():
            raise EndpointConnectionError(endpoint_url='myurl')

        mock_conn = Mock()
        mock_conn.get_send_quota.side_effect = se_get

        with patch('%s.connect' % pb) as mock_connect:
            with patch('%s.logger' % pbm) as mock_logger:
                cls = _SesService(21, 43)
                cls.conn = mock_conn
                cls._update_limits_from_api()
        assert mock_connect.mock_calls == [call()]
        assert mock_conn.mock_calls == [call.get_send_quota()]
        assert mock_logger.mock_calls == [
            call.warn('Skipping SES: %s',
                      'Could not connect to the endpoint URL: "myurl"')
        ]
        assert cls.limits['Daily sending quota'].api_limit is None
 def test_factcache_nonmatching_old_and_new_fact(self, mock_warn):
     # Set fact style to 'both'
     self.dev._fact_style = 'both'
     # Create a callback for the foo fact.
     self.dev.facts._callbacks['foo'] = get_foo_fact
     # Cache the new-style foo fact
     self.dev.facts._cache['foo'] = 'foo'
     # Set the old-style foo fact to a different value
     self.dev._ofacts['foo'] = 'bar'
     # Now, trying to access the foo fact should cause a
     # RunTimeWarning because the values of the new and old-style facts
     # do not match
     foo = self.dev.facts['foo']
     mock_warn.assert_has_calls([call.warn(
         'New and old-style facts do not '
                                  'match for the foo fact.\n'
                                  '    New-style value: foo\n'
                                  '    Old-style value: bar\n',
                                 RuntimeWarning)])
    def test_update_limits_from_api_invalid_region(self):
        def se_get():
            raise EndpointConnectionError(endpoint_url='myurl')

        mock_conn = Mock()
        mock_conn.get_send_quota.side_effect = se_get

        with patch('%s.connect' % pb) as mock_connect:
            with patch('%s.logger' % pbm) as mock_logger:
                cls = _SesService(21, 43)
                cls.conn = mock_conn
                cls._update_limits_from_api()
        assert mock_connect.mock_calls == [call()]
        assert mock_conn.mock_calls == [call.get_send_quota()]
        assert mock_logger.mock_calls == [
            call.warn(
                'Skipping SES: %s',
                'Could not connect to the endpoint URL: "myurl"'
            )
        ]
        assert cls.limits['Daily sending quota'].api_limit is None
Exemple #21
0
    def test_find_usage_invalid_region(self):
        def se_get():
            raise EndpointConnectionError(endpoint_url='myurl')

        mock_conn = Mock()
        mock_conn.get_send_quota.side_effect = se_get

        with patch('%s.connect' % pb) as mock_connect:
            with patch('%s.logger' % pbm) as mock_logger:
                cls = _SesService(21, 43)
                cls.conn = mock_conn
                assert cls._have_usage is False
                cls.find_usage()
        assert mock_connect.mock_calls == [call()]
        assert cls._have_usage is False
        assert mock_logger.mock_calls == [
            call.debug('Checking usage for service %s', 'SES'),
            call.warn('Skipping SES: %s',
                      'Could not connect to the endpoint URL: "myurl"')
        ]
        assert mock_conn.mock_calls == [call.get_send_quota()]
        assert len(cls.limits['Daily sending quota'].get_current_usage()) == 0
Exemple #22
0
    def test_find_usage_connection_fail(self):
        def conn_err():
            raise EndpointConnectionError(endpoint_url='myurl')

        mock_conn = Mock()
        mock_conn.get_account_settings.side_effect = conn_err

        with patch('%s.connect' % pb) as mock_connect:
            with patch('%s.logger' % pbm) as mock_logger:
                cls = _LambdaService(21, 43)
                cls.conn = mock_conn
                cls.find_usage()

        assert len(cls.limits) == 6
        assert mock_connect.mock_calls == [call()]
        assert mock_conn.mock_calls == [call.get_account_settings()]
        assert mock_logger.mock_calls == [
            call.debug('Getting limits for Lambda'),
            call.debug('Getting usage for Lambda metrics'),
            call.warn('Skipping Lambda: %s',
                      'Could not connect to the endpoint URL: "myurl"')
        ]
    def test_find_usage_invalid_region(self):
        def se_get():
            raise EndpointConnectionError(endpoint_url='myurl')

        mock_conn = Mock()
        mock_conn.get_send_quota.side_effect = se_get

        with patch('%s.connect' % pb) as mock_connect:
            with patch('%s.logger' % pbm) as mock_logger:
                cls = _SesService(21, 43)
                cls.conn = mock_conn
                assert cls._have_usage is False
                cls.find_usage()
        assert mock_connect.mock_calls == [call()]
        assert cls._have_usage is False
        assert mock_logger.mock_calls == [
            call.debug('Checking usage for service %s', 'SES'),
            call.warn(
                'Skipping SES: %s',
                'Could not connect to the endpoint URL: "myurl"'
            )
        ]
        assert mock_conn.mock_calls == [call.get_send_quota()]
        assert len(cls.limits['Daily sending quota'].get_current_usage()) == 0
Exemple #24
0
 def test_rpcmeta_exec_rpc_format_json_lt_14_2(self, mock_warn):
     self.dev._conn.rpc = MagicMock(side_effect=self._mock_manager)
     self.dev.facts._cache['version_info'] = version_info('13.1X46-D15.3')
     self.rpc.get_system_users_information(dict(format='json'))
     mock_warn.assert_has_calls([call.warn(
         'Native JSON support is only from 14.2 onwards', RuntimeWarning)])