示例#1
0
def test_restore_all_backup(mocker):
    from console.services.app_actions.app_deploy import MarketService
    service = ServiceSourceInfo()
    service.service_id = "dummy service_id"
    market_service = MarketService(None, service, "dummy version")
    backup = TenantServiceBackup()
    market_service.restore_func = {
        "deploy_version": market_service.dummy_func,
        "app_version": market_service.dummy_func,
        "image": market_service.dummy_func,
        "slug_path": market_service.dummy_func,
        "envs": market_service.dummy_func,
        "connect_infos": market_service.dummy_func,
        "ports": market_service.dummy_func,
        "volumes": market_service.dummy_func,
        "probe": market_service.dummy_func,
        "dep_services": market_service.dummy_func,
        "dep_volumes": market_service.dummy_func,
        "plugins": market_service.dummy_func,
    }
    logger.debug("market_service.async_action: {}".format(
        market_service.async_action))
    market_service.restore_backup(backup)
    assert 0 == market_service.async_action
    assert 0 == market_service.get_async_action()
示例#2
0
    def _update_component_source(self,
                                 component_source: ServiceSourceInfo,
                                 version,
                                 tmpl: map = None):
        extend_info = json.loads(component_source.extend_info)

        if tmpl:
            service_image = tmpl.get("service_image")
            if type(service_image) is dict:
                for key in service_image:
                    extend_info[key] = service_image[key]

            extend_info["source_deploy_version"] = tmpl.get("deploy_version")
            extend_info["source_service_share_uuid"] = tmpl.get(
                "service_share_uuid") if tmpl.get("service_share_uuid",
                                                  None) else tmpl.get(
                                                      "service_key", "")
        update_time = self.app_template.get("update_time")
        if update_time:
            if type(update_time) == datetime:
                extend_info["update_time"] = update_time.strftime(
                    '%Y-%m-%d %H:%M:%S')
            elif type(update_time) == str:
                extend_info["update_time"] = update_time

        component_source.extend_info = json.dumps(extend_info)
        component_source.version = version
示例#3
0
def test_update_changed(mocker):
    from console.services.app_actions.app_deploy import MarketService
    service = ServiceSourceInfo()
    service.service_id = "dummy service_id"
    market_service = MarketService(None, service, "dummy version")
    market_service._update_changed()
    for k, v in list(market_service.changed.items()):
        continue
示例#4
0
def test_record_not_found(mocker):
    with pytest.raises(RecordNotFound):
        from console.services.app_actions.properties_changes import PropertiesChanges
        service_source = ServiceSourceInfo()
        service_source.group_key = "dummy group_key"
        mocker.patch(
            "console.repositories.app.service_source_repo.get_service_source",
            return_value=service_source)
        properties_changes = PropertiesChanges(TenantServiceInfo())
        properties_changes.get_property_changes("eid", "version")
示例#5
0
 def _create_component(snap):
     # component
     component = TenantServiceInfo(**snap["service_base"])
     # component source
     component_source = ServiceSourceInfo(**snap["service_source"])
     # environment
     envs = [TenantServiceEnvVar(**env) for env in snap["service_env_vars"]]
     # ports
     ports = [TenantServicesPort(**port) for port in snap["service_ports"]]
     # service_extend_method
     extend_info = ServiceExtendMethod(**snap["service_extend_method"])
     # volumes
     volumes = [TenantServiceVolume(**volume) for volume in snap["service_volumes"]]
     # configuration files
     config_files = [TenantServiceConfigurationFile(**config_file) for config_file in snap["service_config_file"]]
     # probe
     probes = [ServiceProbe(**probe) for probe in snap["service_probes"]]
     # monitors
     monitors = [ServiceMonitor(**monitor) for monitor in snap["service_monitors"]]
     # graphs
     graphs = [ComponentGraph(**graph) for graph in snap["component_graphs"]]
     return Component(
         component=component,
         component_source=component_source,
         envs=envs,
         ports=ports,
         volumes=volumes,
         config_files=config_files,
         probe=probes[0] if probes else None,
         extend_info=extend_info,
         monitors=monitors,
         graphs=graphs,
         plugin_deps=[],
     )
示例#6
0
def test_list_by_svc_share_uuids():
    tenant_id = "6d1c06e1d9e84d57aeb42ea80d49018a"
    service_id = "560ca84003254737a426d0bd5f513afd"
    service_cname = "WordPress"
    group_id = 20
    service = TenantServiceInfo()
    service.tenant_id = tenant_id
    service.service_id = service_id
    service.service_cname = service_cname
    service.save()

    service_source = ServiceSourceInfo()
    service_source.team_id = tenant_id
    service_source.service_id = service_id
    service_source.service_share_uuid = "2669c2cec6bc7bf5aab29a0ea2703d66"
    service_source.save()

    group_relation = ServiceGroupRelation()
    group_relation.service_id = service_id
    group_relation.group_id = group_id
    group_relation.save()

    from console.repositories.app import service_repo
    result = service_repo.list_by_svc_share_uuids(
        group_id, ["2669c2cec6bc7bf5aab29a0ea2703d66"])
    service = result[0]
    assert service.get("service_id") == service_id
    assert service.get("service_cname") == service_cname
示例#7
0
def test_rbd_app_not_found(mocker):
    from console.services.app_actions.properties_changes import PropertiesChanges

    with open("{}/tests/console/svcupgrade/app_template.json".format(settings.BASE_DIR)) as json_file:
        app_template = json.load(json_file)
        rain_app = RainbondCenterApp()
        rain_app.app_template = json.dumps(app_template)
    mocker.patch("console.repositories.market_app_repo.rainbond_app_repo.get_enterpirse_app_by_key_and_version",
                 return_value=rain_app)

    service_source = ServiceSourceInfo()
    service_source.group_key = "dummy group_key"
    mocker.patch("console.repositories.app.service_source_repo.get_service_source",
                 return_value=service_source)

    with pytest.raises(RbdAppNotFound):
        properties_changes = PropertiesChanges(TenantServiceInfo(), Tenants())
        properties_changes.get_property_changes("eid", "version")
示例#8
0
 def _create_component(self, snap):
     # component
     component = TenantServiceInfo(**snap["service_base"])
     # component source
     component_source = ServiceSourceInfo(**snap["service_source"])
     # environment
     envs = [TenantServiceEnvVar(**env) for env in snap["service_env_vars"]]
     # ports
     ports = [TenantServicesPort(**port) for port in snap["service_ports"]]
     # service_extend_method
     extend_info = None
     if snap.get("service_extend_method"):
         extend_info = ServiceExtendMethod(
             **snap.get("service_extend_method"))
     # volumes
     volumes = [
         TenantServiceVolume(**volume) for volume in snap["service_volumes"]
     ]
     # configuration files
     config_files = [
         TenantServiceConfigurationFile(**config_file)
         for config_file in snap["service_config_file"]
     ]
     # probe
     probes = [ServiceProbe(**probe) for probe in snap["service_probes"]]
     # monitors
     monitors = [
         ServiceMonitor(**monitor) for monitor in snap["service_monitors"]
     ]
     # graphs
     graphs = [
         ComponentGraph(**graph) for graph in snap["component_graphs"]
     ]
     service_labels = [
         ServiceLabels(**label) for label in snap["service_labels"]
     ]
     cpt = Component(
         component=component,
         component_source=component_source,
         envs=envs,
         ports=ports,
         volumes=volumes,
         config_files=config_files,
         probes=probes,
         extend_info=extend_info,
         monitors=monitors,
         graphs=graphs,
         plugin_deps=[],
         labels=service_labels,
         support_labels=self.support_labels,
     )
     cpt.action_type = snap.get("action_type", ActionType.BUILD.value)
     return cpt
 def __save_service_source(self, tenant, service, service_source):
     if service_source:
         service_source.pop("ID")
         new_service_source = ServiceSourceInfo(**service_source)
         new_service_source.service_id = service.service_id
         new_service_source.team_id = tenant.tenant_id
         new_service_source.save()
 def _template_to_component_source(self, component: TenantServiceInfo, tmpl: map):
     extend_info = tmpl.get("service_image")
     extend_info["source_deploy_version"] = tmpl.get("deploy_version")
     extend_info["source_service_share_uuid"] = tmpl.get("service_share_uuid") if tmpl.get(
         "service_share_uuid", None) else tmpl.get("service_key", "")
     if "update_time" in tmpl:
         if type(tmpl["update_time"]) == datetime:
             extend_info["update_time"] = tmpl["update_time"].strftime('%Y-%m-%d %H:%M:%S')
         elif type(tmpl["update_time"]) == str:
             extend_info["update_time"] = tmpl["update_time"]
     if self.install_from_cloud:
         extend_info["install_from_cloud"] = True
         extend_info["market"] = "default"
         extend_info["market_name"] = self.market_name
     return ServiceSourceInfo(
         team_id=component.tenant_id,
         service_id=component.service_id,
         extend_info=json.dumps(extend_info),
         group_key=self.app_model_key,
         version=self.version,
         service_share_uuid=tmpl.get("service_share_uuid")
         if tmpl.get("service_share_uuid", None) else tmpl.get("service_key"),
     )