Ejemplo n.º 1
0
def pick_subscribed_machines(configuration, cred):
    azure_subscription_id = configuration['azure']['subscription_id']
    resource_client = ResourceManagementClient(cred, azure_subscription_id)
    compute_client = ComputeManagementClient(cred, azure_subscription_id)
    resource_groups_list = resource_client.resource_groups.list()
    machines_list_all = compute_client.virtual_machines.list_all()
    rg = configuration['azure']['resource_groups'].split(',')
    machines = pick_machines(resource_groups_list, machines_list_all, rg)
    return machines
Ejemplo n.º 2
0
def test_pick_machines_with_one_fitting_vm():
    subscribed_resource_groups = [
        MyResourceGroup(id='1234/res_group_one', name='res_group_one'),
        MyResourceGroup(id='9876/res_group_two', name='res_group_two')
    ]
    subscribed_machines = [MyVirtualMachine(id='1234/res_group_one/myvmname')]
    configured_resource_groups = 'res_group_one,res_group_two'.split(',')
    machines = pick_machines(subscribed_resource_groups, subscribed_machines,
                             configured_resource_groups)

    assert len(machines) == 1
Ejemplo n.º 3
0
def test_pick_machines_with_no_subscribed_machines():
    subscribed_resource_groups = [
        MyResourceGroup(id='1234/res_group_one', name='res_group_one'),
        MyResourceGroup(id='1234/res_group_one', name='res_group_two')
    ]
    subscribed_machines = []
    configured_resource_groups = 'res_group_one,res_group_two'.split(',')
    machines = pick_machines(subscribed_resource_groups, subscribed_machines,
                             configured_resource_groups)

    assert len(machines) == 0
Ejemplo n.º 4
0
def describe_machines(configuration: Configuration = None,
                      secrets: Secrets = None, filter: str = None):
    """
    Describe Azure virtual machines.

    Parameters
    ----------
    filter : str
        Filter the virtual machines. If the filter is omitted all machines in
        the subscription will be selected for the probe.
        Filtering example:
        'where resourceGroup=="myresourcegroup" and name="myresourcename"'
    """
    logger.debug("Start describe_machines: configuration='{}', filter='{}'"
                 .format(configuration, filter))
    machines = pick_machines(configuration, secrets, filter)
    return machines
Ejemplo n.º 5
0
def restart_machine(configuration: Configuration = None,
                    secrets: Secrets = None,
                    filter: str = None):
    """
    Restart a virtual machines at random.

    Parameters
    ----------
    filter : str
        Filter the virtual machines. If the filter is omitted all machines in
        the subscription will be selected as potential chaos candidates.
        Filtering example:
        'where resourceGroup=="myresourcegroup" and name="myresourcename"'
    """
    logger.debug(
        "Start restart_machine: configuration='{}', filter='{}'".format(
            configuration, filter))

    machines = pick_machines(configuration, secrets, filter)
    choice = random.choice(machines)

    command = restart_machine_command(choice)
    execute(configuration, secrets, command)
Ejemplo n.º 6
0
def test_pick_machines_with_empty_arguments():
    subscribed_resource_groups = []
    subscribed_machines = []
    machines = pick_machines(subscribed_resource_groups, subscribed_machines)

    assert len(machines) == 0