Exemple #1
0
    def test_display(self, mocker):
        subject = SelectCommand('Bob', None, 'greets')
        mock_print = mocker.patch('__builtin__.print')
        subject.display()

        mock_print.assert_called_with(
            "\tBob---------------> Prompts for instance name then greets the instance(s) specified"
        )
Exemple #2
0
    def test_construction(self):
        def run_it():
            return 'I ran'

        subject = SelectCommand('Bob', run_it, 'greets')

        assert subject.name == 'Bob'
        assert subject.info == 'greets'
        assert subject.sub_fn() == 'I ran'
Exemple #3
0
    def test_run_for_all(self, instances):
        ran_for = []

        def run_for(whom):
            ran_for.append(whom)

        subject = SelectCommand('Bob', run_for, 'greets')

        subject.run_for('   all')

        assert ran_for == ['Anakin', 'Obi-Wan', 'Ahsoka']
Exemple #4
0
    def test_run_for_specific_instances(self, instances):
        ran_for = []

        def run_for(whom):
            ran_for.append(whom)

        subject = SelectCommand('Bob', run_for, 'greets')

        subject.run_for('third first third')

        assert ran_for == ['Anakin', 'Ahsoka']
Exemple #5
0
    def test_all_when_prompted_finishes(self, instances, mocker):
        mock_input = mocker.patch('__builtin__.raw_input')
        mock_input.return_value = 'all'
        ran_for = []

        def run_for(whom):
            ran_for.append(whom)

        subject = SelectCommand('Bob', run_for, 'greets')

        subject.run_for('')

        assert ran_for == ['Anakin', 'Obi-Wan', 'Ahsoka']
Exemple #6
0
    def test_run_for_with_no_input_will_prompt(self, instances, mocker):
        mock_input = mocker.patch('__builtin__.raw_input')
        mock_input.side_effect = ['first', '']
        ran_for = []

        def run_for(whom):
            ran_for.append(whom)

        subject = SelectCommand('Bob', run_for, 'greets')

        subject.run_for('')

        assert ran_for == ['Anakin']
Exemple #7
0
    def test_complains_when_instance_is_not_known(self, instances, mocker):
        mock_input = mocker.patch('__builtin__.raw_input')
        mock_input.side_effect = ['first', '']
        mock_print = mocker.patch('__builtin__.print')

        ran_for = []

        def run_for(whom):
            ran_for.append(whom)

        subject = SelectCommand('Bob', run_for, 'greets')

        subject.run_for('notaninstance')

        mock_print.assert_called_with(
            "\tno known instance called notaninstance")
        assert ran_for == ['Anakin']
Exemple #8
0
def _finish_test():
    prompt = True
    dst_dir = ""
    while prompt:
        dst_dir = raw_input("\tPlease enter a new directory name for the logs (blank line to cancel): ").strip()
        if ' ' in dst_dir:
            print("\tERROR please no spaces, try again\n")
            prompt = True
        elif os.path.exists(dst_dir):
            print("\tERROR %s already exists, try again\n" % dst_dir)
            prompt = True
        else:
            prompt = False

    if dst_dir == '':
        return

    os.mkdir(dst_dir)
    SelectCommand('internal', lambda instance: _finish_instance(instance, dst_dir), 'internal').run_for('all')
Exemple #9
0
def command():
    return SelectCommand(name(), _kill, "shuts down")
Exemple #10
0
# Copyright (c) 2019, Substratum LLC (https://substratum.net) and/or its affiliates. All rights reserved.
from command import SelectCommand, SetCommand
import finish, info, init, nfo, update, kill, start, help, daisy, cluster, binaries_command

COMMANDS = {
    init.name():
    init.command(),  # setup
    info.name():
    info.command(),  # always "all"
    update.name():
    update.command(),
    start.name():
    start.command(),
    'tail':
    SelectCommand('tail', lambda instance: instance.tail(),
                  "opens terminal(s) to tail -f MASQNode logs on"),
    'subvert':
    SelectCommand('subvert', lambda instance: instance.subvert(), "subverts"),
    'curl':
    SelectCommand('curl', lambda instance: instance.curl(),
                  "prompts for URL and curl count, and executes on"),
    'wget':
    SelectCommand('wget', lambda instance: instance.wget(),
                  "wgets traffic on"),
    'verify':
    SelectCommand('verify', lambda instance: instance.verify(),
                  "checks whether traffic was routed for"),
    'revert':
    SelectCommand('revert', lambda instance: instance.revert(),
                  "reverts and cleans up traffic generation on"),
    'inspect':
Exemple #11
0
def command():
    return SelectCommand(
        name(),
        _update,
        "sends updated binaries (from pwd) and then nfo"
    )
Exemple #12
0
def command():
    return SelectCommand(
        name(), _nfo,
        "nukes from orbit - it's the only way to be sure. Restarts")
Exemple #13
0
def command():
    return SelectCommand(name(), _start_node, "starts SubstratumNode on")
Exemple #14
0
def command():
    return SelectCommand(name(), _start_node, "starts MASQNode on")
Exemple #15
0
 def __init__(self):
     SelectCommand.__init__(
         self, "binaries", lambda: 0,
         "assigns binaries in /binaries subdirectory to a Node before it is started"
     )