def test_can_provision_instances_according_to_sct_configuration(params, test_config, azure_service, fake_remoter):
    """Integration test for provisioning sct resources according to SCT configuration."""
    fake_remoter.result_map = {r"sudo cloud-init status --wait": Result(stdout="..... \n status: done", stderr="nic", exited=0),
                               r"ls /tmp/cloud-init": Result(stdout="done", exited=0)}
    tags = TestConfig.common_tags()
    provision_sct_resources(params=params, test_config=test_config, azure_service=azure_service)
    provisioner_eastus = provisioner_factory.create_provisioner(
        backend="azure", test_id=params.get("test_id"), region="eastus", azure_service=azure_service)
    eastus_instances = provisioner_eastus.list_instances()
    db_nodes = [node for node in eastus_instances if node.tags['NodeType'] == "scylla-db"]
    loader_nodes = [node for node in eastus_instances if node.tags['NodeType'] == "loader"]
    monitor_nodes = [node for node in eastus_instances if node.tags['NodeType'] == "monitor"]

    assert len(db_nodes) == 3
    assert len(loader_nodes) == 2
    assert len(monitor_nodes) == 1
    db_node = db_nodes[0]
    assert db_node.region == "eastus"
    assert list(db_node.tags.keys()) == list(tags.keys()) + ["NodeType", "keep_action", "NodeIndex"]
    assert db_node.pricing_model == PricingModel.SPOT

    provisioner_easteu = provisioner_factory.create_provisioner(backend="azure", test_id=params.get("test_id"),
                                                                region="easteu", azure_service=azure_service)
    easteu_instances = provisioner_easteu.list_instances()
    db_nodes = [node for node in easteu_instances if node.tags['NodeType'] == "scylla-db"]
    loader_nodes = [node for node in easteu_instances if node.tags['NodeType'] == "loader"]
    monitor_nodes = [node for node in easteu_instances if node.tags['NodeType'] == "monitor"]

    assert len(db_nodes) == 1
    assert len(loader_nodes) == 0
    assert len(monitor_nodes) == 0
    db_node = db_nodes[0]
    assert db_node.region == "easteu"
    assert list(db_node.tags.keys()) == list(tags.keys()) + ["NodeType", "keep_action", "NodeIndex"]
    assert db_node.pricing_model == PricingModel.SPOT
Пример #2
0
def test_can_add_tags(provisioner, definition, backend, provisioner_params):
    provisioner.add_instance_tags(definition.name, {"tag_key": "tag_value"})
    assert provisioner.get_or_create_instance(definition).tags.get(
        "tag_key") == "tag_value"

    # validate real tags change
    provisioner = provisioner_factory.create_provisioner(backend=backend,
                                                         **provisioner_params)
    assert provisioner.get_or_create_instance(definition).tags.get(
        "tag_key") == "tag_value"
Пример #3
0
def test_can_terminate_vm_instance(provisioner, definition, backend,
                                   provisioner_params):
    """should read from cache instead creating anything - so should be fast (after provisioner initialized)"""
    provisioner.terminate_instance(definition.name, wait=True)

    # validate cache has been cleaned up
    assert not provisioner.list_instances()

    # validate real termination
    provisioner = provisioner_factory.create_provisioner(backend=backend,
                                                         **provisioner_params)
    assert not provisioner.list_instances()
Пример #4
0
def test_can_trigger_cleanup(definition, provisioner, backend,
                             provisioner_params):  # pylint: disable=no-self-use
    provisioner.get_or_create_instance(definition)
    assert len(provisioner.list_instances()) == 1
    provisioner.cleanup(wait=True)

    # validate cache has been cleaned up
    assert not provisioner.list_instances()

    # validate real termination
    provisioner = provisioner_factory.create_provisioner(backend=backend,
                                                         **provisioner_params)
    assert not provisioner.list_instances(), "failed cleaning up resources"
Пример #5
0
def test_can_provision_scylla_vm(region, definition, provisioner, backend,
                                 provisioner_params):
    v_m = provisioner.get_or_create_instances(definitions=[definition])[0]
    assert v_m.name == definition.name
    assert v_m.region == region
    assert v_m.user_name == definition.user_name
    assert v_m.public_ip_address
    assert v_m.private_ip_address
    assert v_m.tags == definition.tags

    assert v_m == provisioner.list_instances()[0]

    v_m_2 = provisioner.get_or_create_instance(definition)
    assert v_m is v_m_2, 'provisioner should not not recreate vm with the same name'

    provisioner = provisioner_factory.create_provisioner(backend=backend,
                                                         **provisioner_params)
    v_m._provisioner = provisioner  # pylint: disable=protected-access
    assert v_m == provisioner.list_instances(
    )[0], 'provisioner with the same params should rediscover created resources'
def test_fallback_on_demand_when_spot_fails(fallback_on_demand, params, test_config, azure_service, fake_remoter):
    # pylint: disable=unused-argument
    fake_remoter.result_map = {r"sudo cloud-init status --wait": Result(stdout="..... \n status: done", stderr="nic", exited=0),
                               r"ls /tmp/cloud-init": Result(stdout="done", exited=0)}
    provision_sct_resources(params=params, test_config=test_config, azure_service=azure_service)
    provisioner_eastus = provisioner_factory.create_provisioner(
        backend="azure", test_id=params.get("test_id"), region="eastus", azure_service=azure_service)
    eastus_instances = provisioner_eastus.list_instances()
    db_nodes = [node for node in eastus_instances if node.tags['NodeType'] == "scylla-db"]
    loader_nodes = [node for node in eastus_instances if node.tags['NodeType'] == "loader"]
    monitor_nodes = [node for node in eastus_instances if node.tags['NodeType'] == "monitor"]

    assert len(db_nodes) == 3
    assert len(loader_nodes) == 2
    assert len(monitor_nodes) == 1
    for node in db_nodes:
        assert node.pricing_model == PricingModel.ON_DEMAND
    for node in loader_nodes:
        assert node.pricing_model == PricingModel.SPOT
    for node in monitor_nodes:
        assert node.pricing_model == PricingModel.SPOT
 def _create_instance(self,  # pylint: disable=too-many-arguments
                      instance_type: str,
                      base_image: Any,
                      tags: dict[str, str],
                      instance_name: str,
                      root_disk_size_gb: int = 0,
                      region_az: str = "",
                      test_duration: Optional[int] = None) -> Any:
     if base_image is self.BASE_IMAGE:
         azure_region = self.azure_region_source
         additional_kwargs = {
             "os_state": AzureOsState.GENERALIZED,
             "computer_name": self.image_name.replace(".", "-"),
             "admin_username": self.LOGIN_USER,
             "admin_public_key": self.key_pair.public_key.decode(),
         }
         return azure_region.create_virtual_machine(
             vm_name=instance_name,
             vm_size=instance_type,
             image=base_image,
             disk_size=root_disk_size_gb or self.instance_root_disk_size(test_duration=test_duration),
             tags=tags | {"launch_time": get_current_datetime_formatted()},
             **additional_kwargs,
         )
     else:
         test_id = tags["TestId"]
         provisioner = provisioner_factory.create_provisioner(backend="azure", test_id=test_id,
                                                              region=self.azure_region.location)
         vm_params = InstanceDefinition(name=instance_name,
                                        image_id=base_image["id"],
                                        type=instance_type,
                                        user_name=self.LOGIN_USER,
                                        ssh_key=self.key_pair,
                                        tags=tags | {"launch_time": get_current_datetime_formatted()},
                                        root_disk_size=root_disk_size_gb or self.instance_root_disk_size(
                                            test_duration=test_duration),
                                        user_data=None)
         return provisioner.get_or_create_instance(definition=vm_params,
                                                   pricing_model=PricingModel.ON_DEMAND)
Пример #8
0
def provisioner(backend, provisioner_params):
    return provisioner_factory.create_provisioner(backend,
                                                  **provisioner_params)