def yaml_release_data(bk_user, cluster_id, yaml_template, yaml_version_entity, yaml_show_version): instance_entity = { res_name: ids.split(',') for res_name, ids in yaml_version_entity.resource_entity.items() } namespace = 'test' context = ResContext( access_token=bk_user.token.access_token, username=bk_user.username, cluster_id=cluster_id, project_id=yaml_template.project_id, namespace=namespace, template=yaml_template, show_version=yaml_show_version, instance_entity=instance_entity, is_preview=True, namespace_id=1, ) with mock.patch('backend.helm.app.bcs_info_provider.paas_cc', new=FakePaaSCCMod()), mock.patch( 'backend.helm.helm.bcs_variable.paas_cc', new=FakePaaSCCMod()): data_generator = generator.ReleaseDataGenerator(name="gw", res_ctx=context) release_data = data_generator.generate() return release_data
def form_release_data(bk_user, cluster_id, form_template, form_version_entity, form_show_version): instance_entity = { res_name: ids.split(',') for res_name, ids in form_version_entity.resource_entity.items() } namespace = 'test' context = ResContext( access_token=bk_user.token.access_token, username=bk_user.username, cluster_id=cluster_id, project_id=form_template.project_id, namespace=namespace, template=form_template, show_version=form_show_version, instance_entity=instance_entity, is_preview=True, namespace_id=1, ) with mock.patch( 'backend.templatesets.release.generator.form_mode.get_ns_variable', return_value=(False, '1.12.3', {})), mock.patch( 'backend.templatesets.legacy_apps.instance.generator.paas_cc', new=FakePaaSCCMod()): data_generator = generator.ReleaseDataGenerator(name="nginx", res_ctx=context) release_data = data_generator.generate() return release_data
def test_yaml_generator(self, bk_user, cluster_id, yaml_template, yaml_version_entity, yaml_show_version): instance_entity = { res_name: ids.split(',') for res_name, ids in yaml_version_entity.resource_entity.items() } namespace = 'test' context = ResContext( access_token=bk_user.token.access_token, username=bk_user.username, cluster_id=cluster_id, project_id=yaml_template.project_id, namespace=namespace, template=yaml_template, show_version=yaml_show_version, instance_entity=instance_entity, extras={'namespace_id': 1}, ) with mock.patch('backend.bcs_k8s.app.bcs_info_provider.paas_cc', new=FakePaaSCCMod()), mock.patch( 'backend.bcs_k8s.helm.bcs_variable.paas_cc', new=FakePaaSCCMod()): data_generator = generator.ReleaseDataGenerator(name="gw", res_ctx=context) release_data = data_generator.generate() assert len(release_data.resource_list) == 4 for res in release_data.resource_list: assert res.name == getitems(res.manifest, 'metadata.name') assert res.kind == getitems(res.manifest, 'kind') assert res.namespace == getitems(res.manifest, 'metadata.namespace') assert res.version == yaml_show_version.name if res.kind == 'Endpoints': assert getitems( res.manifest, 'subsets')[0]['addresses'][0]['ip'] == '0.0.0.1' continue if res.kind == 'Pod': assert getitems( res.manifest, 'spec.containers')[0]['image'] == 'redis:5.0.4'
def patch_permissions(): """Patch permission checks to allow API requests, includes: - paas_cc module: return faked project infos - ProjectPermission: allow all permission checks - get_api_public_key: return None """ with mock.patch('backend.utils.permissions.paas_cc', new=FakePaaSCCMod()), mock.patch( 'backend.utils.permissions.paas_auth', new=FakeProjectPermissionAllowAll() ), mock.patch( 'backend.utils.permissions.permissions.ProjectPermission', new=FakeProjectPermissionAllowAll ), mock.patch( 'backend.uniapps.application.base_views.paas_cc', new=FakePaaSCCMod() ), mock.patch( 'backend.apps.utils.paas_cc', new=FakePaaSCCMod() ), mock.patch( 'backend.components.apigw.get_api_public_key', return_value=None ): yield
def test_form_generator(self, bk_user, cluster_id, form_template, form_version_entity, form_show_version): instance_entity = { res_name: ids.split(',') for res_name, ids in form_version_entity.resource_entity.items() } namespace = 'test' context = ResContext( access_token=bk_user.token.access_token, username=bk_user.username, cluster_id=cluster_id, project_id=form_template.project_id, namespace=namespace, template=form_template, show_version=form_show_version, instance_entity=instance_entity, extras={'namespace_id': 1}, ) with mock.patch( 'backend.apps.templatesets.release.generator.form_mode.get_ns_variable', return_value=(False, '1.12.3', {})), mock.patch( 'backend.apps.instance.generator.paas_cc', new=FakePaaSCCMod()): data_generator = generator.ReleaseDataGenerator(name="nginx", res_ctx=context) release_data = data_generator.generate() for res in release_data.resource_list: assert res.name == getitems(res.manifest, 'metadata.name') assert res.kind == getitems(res.manifest, 'kind') assert res.namespace == getitems(res.manifest, 'metadata.namespace') assert res.version == form_show_version.name assert getitems(res.manifest, 'webCache') is None assert 'io.tencent.bcs.cluster' in getitems( res.manifest, 'metadata.annotations') if res.kind == 'Service': assert getitems(res.manifest, 'spec.type') == 'ClusterIP'
def patch_paas_cc(): with mock.patch('backend.container_service.clusters.base.utils.paas_cc', new=FakePaaSCCMod()): yield