예제 #1
0
def test_wait_for_deployment(mock_sleep, mock_are_instances_deployed,
                             mock__log,
                             mock_get_cluster_instance_map_for_service):
    mock_cluster_map = {
        'cluster1': {
            'instances': ['instance1', 'instance2', 'instance3']
        }
    }
    mock_get_cluster_instance_map_for_service.return_value = mock_cluster_map

    mock_are_instances_deployed.side_effect = are_instances_deployed_side_effect
    mock_sleep.side_effect = TimeoutError()
    with raises(TimeoutError):
        mark_for_deployment.wait_for_deployment('service', 'deploy_group_1',
                                                'somesha', '/nail/soa', 1)
    mock_get_cluster_instance_map_for_service.assert_called_with(
        '/nail/soa', 'service', 'deploy_group_1')
    mock_are_instances_deployed.assert_called_with(
        cluster='cluster1',
        service='service',
        instances=mock_cluster_map['cluster1']['instances'],
        git_sha='somesha')

    mock_cluster_map = {
        'cluster1': {
            'instances': ['instance1', 'instance2']
        },
        'cluster2': {
            'instances': ['instance1', 'instance2']
        }
    }
    mock_get_cluster_instance_map_for_service.return_value = mock_cluster_map
    mark_for_deployment.wait_for_deployment('service', 'deploy_group_1',
                                            'somesha', '/nail/soa', 1)

    mock_cluster_map = {
        'cluster1': {
            'instances': ['instance1', 'instance2']
        },
        'cluster2': {
            'instances': ['instance1', 'instance3']
        }
    }
    mock_get_cluster_instance_map_for_service.return_value = mock_cluster_map
    with raises(TimeoutError):
        mark_for_deployment.wait_for_deployment('service', 'deploy_group_1',
                                                'somesha', '/nail/soa', 1)
예제 #2
0
    assert process_inotify_mock.call_args[0][0][3] == b'mydep.depinstance.json'
    assert process_inotify_mock.call_args[0][1] == {}


@mock.patch.object(firewall, 'firewall_flock', autospec=True)
@mock.patch.object(firewall, 'general_update', autospec=True)
def test_run_cron(mock_general_update, mock_firewall_flock, mock_cron_args):
    firewall_update.run_cron(mock_cron_args)
    assert mock_general_update.called is True
    assert mock_firewall_flock.return_value.__enter__.called is True


@mock.patch.object(firewall,
                   'firewall_flock',
                   autospec=True,
                   side_effect=TimeoutError('Oh noes'))
@mock.patch.object(firewall, 'general_update', autospec=True)
def test_run_cron_flock_error(mock_general_update, mock_firewall_flock,
                              mock_cron_args):
    with pytest.raises(TimeoutError):
        firewall_update.run_cron(mock_cron_args)


@mock.patch.object(firewall_update, 'log', autospec=True)
@mock.patch.object(firewall_update.firewall,
                   'ensure_service_chains',
                   autospec=True)
@mock.patch.object(firewall_update.firewall,
                   'active_service_groups',
                   autospec=True)
@mock.patch.object(firewall, 'firewall_flock', autospec=True)
 def mock_sleep_side_effect(self, time):
     if self.call_count == 5:
         raise TimeoutError()
     self.call_count += 1
     return
예제 #4
0
        firewall_update.run_daemon(mock_daemon_args)
    assert smartstack_deps_mock.call_count > 0
    assert process_inotify_mock.call_args[0][0][3] == b"mydep.depinstance.json"
    assert process_inotify_mock.call_args[0][1] == {}


@mock.patch.object(firewall, "firewall_flock", autospec=True)
@mock.patch.object(firewall, "general_update", autospec=True)
def test_run_cron(mock_general_update, mock_firewall_flock, mock_cron_args):
    firewall_update.run_cron(mock_cron_args)
    assert mock_general_update.called is True
    assert mock_firewall_flock.return_value.__enter__.called is True


@mock.patch.object(
    firewall, "firewall_flock", autospec=True, side_effect=TimeoutError("Oh noes")
)
@mock.patch.object(firewall, "general_update", autospec=True)
def test_run_cron_flock_error(mock_general_update, mock_firewall_flock, mock_cron_args):
    with pytest.raises(TimeoutError):
        firewall_update.run_cron(mock_cron_args)


@mock.patch.object(firewall_update, "log", autospec=True)
@mock.patch.object(firewall_update.firewall, "ensure_service_chains", autospec=True)
@mock.patch.object(firewall_update.firewall, "active_service_groups", autospec=True)
@mock.patch.object(firewall, "firewall_flock", autospec=True)
def test_process_inotify_event(
    firewall_flock_mock,
    active_service_groups_mock,
    ensure_service_chains_mock,
예제 #5
0
    assert process_inotify_mock.call_args[0][0][3] == b"mydep.depinstance.json"
    assert process_inotify_mock.call_args[0][1] == {}


@mock.patch.object(firewall, "firewall_flock", autospec=True)
@mock.patch.object(firewall, "general_update", autospec=True)
def test_run_cron(mock_general_update, mock_firewall_flock, mock_cron_args):
    firewall_update.run_cron(mock_cron_args)
    assert mock_general_update.called is True
    assert mock_firewall_flock.return_value.__enter__.called is True


@mock.patch.object(firewall,
                   "firewall_flock",
                   autospec=True,
                   side_effect=TimeoutError("Oh noes"))
@mock.patch.object(firewall, "general_update", autospec=True)
def test_run_cron_flock_error(mock_general_update, mock_firewall_flock,
                              mock_cron_args):
    with pytest.raises(TimeoutError):
        firewall_update.run_cron(mock_cron_args)


@mock.patch.object(firewall_update, "log", autospec=True)
@mock.patch.object(firewall_update.firewall,
                   "ensure_service_chains",
                   autospec=True)
@mock.patch.object(firewall_update.firewall,
                   "active_service_groups",
                   autospec=True)
@mock.patch.object(firewall, "firewall_flock", autospec=True)
예제 #6
0
    with pytest.raises(StopIteration):
        firewall_update.run_daemon(mock_daemon_args)
    assert smartstack_deps_mock.call_count > 0
    assert process_inotify_mock.call_args[0][0][3] == b'mydep.depinstance.json'
    assert process_inotify_mock.call_args[0][1] == {}


@mock.patch.object(firewall, 'firewall_flock', autospec=True)
@mock.patch.object(firewall, 'general_update', autospec=True)
def test_run_cron(mock_general_update, mock_firewall_flock, mock_cron_args):
    firewall_update.run_cron(mock_cron_args)
    assert mock_general_update.called is True
    assert mock_firewall_flock.return_value.__enter__.called is True


@mock.patch.object(firewall, 'firewall_flock', autospec=True, side_effect=TimeoutError('Oh noes'))
@mock.patch.object(firewall, 'general_update', autospec=True)
def test_run_cron_flock_error(mock_general_update, mock_firewall_flock, mock_cron_args):
    with pytest.raises(TimeoutError):
        firewall_update.run_cron(mock_cron_args)


@mock.patch.object(firewall_update, 'log', autospec=True)
@mock.patch.object(firewall_update.firewall, 'ensure_service_chains', autospec=True)
@mock.patch.object(firewall_update.firewall, 'active_service_groups', autospec=True)
@mock.patch.object(firewall, 'firewall_flock', autospec=True)
def test_process_inotify_event(firewall_flock_mock, active_service_groups_mock, ensure_service_chains_mock, log_mock):
    active_service_groups_mock.return_value = {
        firewall.ServiceGroup('myservice', 'myinstance'): {'00:00:00:00:00:00'},
        firewall.ServiceGroup('anotherservice', 'instance'): {'11:11:11:11:11:11'},
        firewall.ServiceGroup('thirdservice', 'instance'): {'22:22:22:22:22:22'},