Example #1
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.paasta_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
Example #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.paasta_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
Example #3
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
Example #4
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