Пример #1
0
    def test_suggest_smartstack_proxy_port_too_many_services(self):
        """If all the ports are taken, we should raise an error"""
        yelpsoa_config_root = "fake_yelpsoa_config_root"
        walk_return = [
            ("fake_root1", "fake_dir1", ["smartstack.yaml"]),
            ("fake_root2", "fake_dir2", ["smartstack.yaml"]),
            ("fake_root3", "fake_dir3", ["smartstack.yaml"]),
        ]
        mock_walk = mock.Mock(return_value=walk_return)

        # See http://www.voidspace.org.uk/python/mock/examples.html#multiple-calls-with-different-effects
        get_smartstack_proxy_port_from_file_returns = [
            20001,
            20002,
            55555,  # bogus out-of-range value
        ]

        def get_smarstack_proxy_port_from_file_side_effect(*args):
            return get_smartstack_proxy_port_from_file_returns.pop(0)
        mock_get_smartstack_proxy_port_from_file = mock.Mock(side_effect=get_smarstack_proxy_port_from_file_side_effect)
        with nested(
            mock.patch("os.walk", mock_walk),
            mock.patch("paasta_tools.cli.fsm.autosuggest._get_smartstack_proxy_port_from_file",
                       mock_get_smartstack_proxy_port_from_file),
        ):
            with raises(Exception) as exc:
                autosuggest.suggest_smartstack_proxy_port(yelpsoa_config_root, range_min=20001,
                                                          range_max=20002)
            assert "There are no more ports available in the range [20001, 20002]" == str(exc.value)
Пример #2
0
    def test_suggest_smartstack_proxy_port(self):
        yelpsoa_config_root = "fake_yelpsoa_config_root"
        walk_return = [
            ("fake_root1", "fake_dir1", ["service.yaml"]),
            ("fake_root2", "fake_dir2", ["smartstack.yaml"]),
            ("fake_root3", "fake_dir3", ["service.yaml"]),
        ]
        mock_walk = mock.Mock(return_value=walk_return)

        # See http://www.voidspace.org.uk/python/mock/examples.html#multiple-calls-with-different-effects
        get_smartstack_proxy_port_from_file_returns = [
            20001,
            20002,
            55555,  # bogus out-of-range value
        ]

        def get_smarstack_proxy_port_from_file_side_effect(*args):
            return get_smartstack_proxy_port_from_file_returns.pop(0)

        mock_get_smartstack_proxy_port_from_file = mock.Mock(
            side_effect=get_smarstack_proxy_port_from_file_side_effect)
        with nested(
                mock.patch("os.walk", mock_walk),
                mock.patch(
                    "paasta_tools.cli.fsm.autosuggest._get_smartstack_proxy_port_from_file",
                    mock_get_smartstack_proxy_port_from_file),
        ):
            actual = autosuggest.suggest_smartstack_proxy_port(
                yelpsoa_config_root)
        # Sanity check: our mock was called once for each legit port file in
        # walk_return
        assert mock_get_smartstack_proxy_port_from_file.call_count == 3

        # What we came here for: the actual output of the function under test
        assert actual == 20002 + 1  # highest port + 1
Пример #3
0
    def test_suggest_smartstack_proxy_port(self):
        yelpsoa_config_root = "fake_yelpsoa_config_root"
        walk_return = [
            ("fake_root1", "fake_dir1", ["smartstack.yaml"]),
            ("fake_root2", "fake_dir2", ["smartstack.yaml"]),
            ("fake_root3", "fake_dir3", ["smartstack.yaml"]),
        ]
        mock_walk = mock.Mock(return_value=walk_return)

        # See http://www.voidspace.org.uk/python/mock/examples.html#multiple-calls-with-different-effects
        get_smartstack_proxy_port_from_file_returns = [
            20001,
            20002,
            55555,  # bogus out-of-range value
        ]

        def get_smarstack_proxy_port_from_file_side_effect(*args):
            return get_smartstack_proxy_port_from_file_returns.pop(0)
        mock_get_smartstack_proxy_port_from_file = mock.Mock(side_effect=get_smarstack_proxy_port_from_file_side_effect)
        with nested(
            mock.patch("os.walk", mock_walk),
            mock.patch("paasta_tools.cli.fsm.autosuggest._get_smartstack_proxy_port_from_file",
                       mock_get_smartstack_proxy_port_from_file),
        ):
            actual = autosuggest.suggest_smartstack_proxy_port(yelpsoa_config_root, range_min=20001, range_max=20003)
        # Sanity check: our mock was called once for each legit port file in
        # walk_return
        assert mock_get_smartstack_proxy_port_from_file.call_count == 3

        # What we came here for: the actual output of the function under test
        assert actual == 20003  # The only available integer in [20001, 20003]
Пример #4
0
    def test_suggest_smartstack_proxy_port(self, mock_read_etc_services):
        yelpsoa_config_root = "fake_yelpsoa_config_root"
        walk_return = [
            ("fake_root1", "fake_dir1", ["smartstack.yaml"]),
            ("fake_root2", "fake_dir2", ["smartstack.yaml"]),
            ("fake_root3", "fake_dir3", ["smartstack.yaml"]),
        ]
        mock_walk = mock.Mock(return_value=walk_return)

        # See http://www.voidspace.org.uk/python/mock/examples.html#multiple-calls-with-different-effects
        get_smartstack_proxy_ports_from_file_returns = [
            {20001, 20003},
            {20002},
            {55555},  # bogus out-of-range value
        ]

        def get_smarstack_proxy_ports_from_file_side_effect(*args):
            return get_smartstack_proxy_ports_from_file_returns.pop(0)

        mock_get_smartstack_proxy_ports_from_file = mock.Mock(
            side_effect=get_smarstack_proxy_ports_from_file_side_effect)
        with mock.patch("os.walk", mock_walk, autospec=None):
            with mock.patch(
                    "paasta_tools.cli.fsm.autosuggest._get_smartstack_proxy_ports_from_file",
                    mock_get_smartstack_proxy_ports_from_file,
                    autospec=None,
            ):
                actual = autosuggest.suggest_smartstack_proxy_port(
                    yelpsoa_config_root, range_min=20001, range_max=20004)
        # Sanity check: our mock was called once for each legit port file in
        # walk_return
        assert mock_get_smartstack_proxy_ports_from_file.call_count == 3

        # What we came here for: the actual output of the function under test
        assert actual == 20004  # The only available integer in [20001, 20004]
Пример #5
0
def get_smartstack_stanza(yelpsoa_config_root, auto, port):
    """Produce a basic smartstack.yaml in a `format <yelpsoa_configs.html#smartstack-yaml>`_
    PaaSTA can use.
    """
    if port is None:
        suggested_port = suggest_smartstack_proxy_port(yelpsoa_config_root)
        if auto:
            port = suggested_port
        else:
            port = ask("Smartstack proxy_port?", suggested_port)
    smartstack_stanza = {}
    key_name = "main"
    smartstack_stanza[key_name] = {
        "advertise": ["superregion"],
        "discover": "superregion",
        "proxy_port": int(port),
        # Make the service available across all of testopia.
        # See SRV-1715 for more background.
        "extra_advertise": {"ecosystem:testopia": ["ecosystem:testopia"]},
    }
    return smartstack_stanza
Пример #6
0
def get_smartstack_stanza(yelpsoa_config_root, auto, port):
    """Produce a basic smartstack.yaml in a `format <yelpsoa_configs.html#smartstack-yaml>`_
    PaaSTA can use.
    """
    if port is None:
        suggested_port = suggest_smartstack_proxy_port(yelpsoa_config_root)
        if auto:
            port = suggested_port
        else:
            port = ask("Smartstack proxy_port?", suggested_port)
    smartstack_stanza = {}
    key_name = "main"
    smartstack_stanza[key_name] = {
        "advertise": ["superregion"],
        "discover": "superregion",
        "proxy_port": int(port),
        # Make the service available across all of testopia.
        # See SRV-1715 for more background.
        "extra_advertise": {
            "ecosystem:testopia": ["ecosystem:testopia"]
        }
    }
    return smartstack_stanza
Пример #7
0
def get_paasta_config(yelpsoa_config_root):
    variables = {
        'proxy_port': suggest_smartstack_proxy_port(yelpsoa_config_root)
    }
    return variables
Пример #8
0
def get_paasta_config(yelpsoa_config_root):
    variables = {
        'proxy_port': suggest_smartstack_proxy_port(yelpsoa_config_root),
    }
    return variables