Commit 5fedfaf3 authored by lavado's avatar lavado
Browse files

Merge branch 'oai-helm' into 'master'

new oai-helm procedure created

See merge request !197
parents cdedaae5 aff698f2
Pipeline #6541 failed with stage
in 9 seconds
##
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##
import asyncio
import asyncssh
import requests
import logging
import os
from osm_ee.exceptions import VnfException
import osm_ee.util.util_ee as util_ee
import osm_ee.util.util_ansible as util_ansible
import osm_ee.vnf.mylib as mylib
class VnfEE:
PLAYBOOK_PATH = "/app/EE/osm_ee/vnf"
SSH_SCRIPT = "/app/EE/osm_ee/vnf/run_ssh.sh"
def __init__(self, config_params):
self.logger = logging.getLogger('osm_ee.vnf')
self.config_params = config_params
# config method saves SSH access parameters (host and username) for future use by other methods.
# It is mandatory in any case.
async def config(self, id, params):
self.logger.debug("Execute action config, params: {}".format(params))
# Config action is special, params are merged with previous config calls
self.config_params.update(params)
required_params = ["ssh-hostname"]
self._check_required_params(self.config_params, required_params)
yield "OK", "Configured"
# This method implements the "run_script" primitive. Uncomment and modify it if a primitive requires executing a user
# script in the VDU. It needs "file" parameter (script's file to run, must be in "source" directory)
# and optionally "parameters" (command-line arguments for script).
async def run_script(self, id, params):
self.logger.debug("Execute action run_script, params: '{}'".format(params))
self._check_required_params(params, ["file"])
command = "bash " + self.SSH_SCRIPT + " " + self.config_params["ssh-hostname"] + " " + self.config_params["ssh-username"] + " " + params["file"]
if "parameters" in params:
command += " \"" + params.get("parameters", "") + "\""
self.logger.debug("Command: '{}'".format(command))
return_code, stdout, stderr = await util_ee.local_async_exec(command)
if return_code != 0:
yield "ERROR", "return code {}: {}".format(return_code, stderr.decode())
else:
yield "OK", stdout.decode()
# This method implements the "copy_files" primitive. Uncomment and modify it if a primitive requires
# to copy files to a VNF. It needs file name parameter (file must be in "source" directory).
async def copy_files(self, id, params):
self.logger.debug("Execute action copy_files, params: '{}'".format(params))
self._check_required_params(params, ["file"])
command= "scp" + " -o StrictHostKeyChecking=no /app/EE/osm_ee/vnf/" + params["file"] + " " + self.config_params["ssh-username"] + "@" + self.config_params["ssh-hostname"] + ":" + params["file"]
self.logger.debug("Command: '{}'".format(command))
return_code, stdout, stderr = await util_ee.local_async_exec(command)
if return_code != 0:
yield "ERROR", "return code {}: {}".format(return_code, stderr.decode())
else:
yield "OK", stdout.decode()
# This method implements the "ansible_playbook" primitive. Uncomment and modify it if a primitive requires
# executing an Ansible Playbook. It needs "playbook-name" parameter (playbook file, must be in "source" directory).
# async def ansible_playbook(self, id, params):
# self.logger.debug("Execute action ansible_playbook, params: '{}'".format(params))
# try:
# self._check_required_params(params, ["playbook-name"])
# params["ansible_user"] = self.config_params["ssh-username"]
# inventory = self.config_params["ssh-hostname"] + ","
# playbook = self.PLAYBOOK_PATH + "/" + params["playbook-name"]
# os.environ["ANSIBLE_HOST_KEY_CHECKING"] = "False"
# return_code, stdout, stderr = await util_ansible.execute_playbook(playbook, inventory, params)
# status = "OK" if return_code == 0 else "ERROR"
# yield status, stdout + stderr
# except Exception as e:
# self.logger.debug("Error executing ansible playbook: {}".format(repr(e)))
# yield "ERROR", str(e)
# This method implements the "ping" primitive. Uncomment and modify it if a primitive requires
# executing a local command (such as ping) on EE. It uses "ssh-hostname" as ping destination.
# async def ping(self, id, params):
# self.logger.debug("Execute action ping, params: '{}'".format(params))
# command = "ping -c 3 " + self.config_params["ssh-hostname"]
# return_code, stdout, stderr = await util_ee.local_async_exec(command)
# if return_code != 0:
# yield "ERROR", "return code {}: {}".format(return_code, stderr.decode())
# else:
# yield "OK", stdout.decode()
# This method implements the "http_check" primitive. Uncomment and modify it if a primitive requires
# executing embedded python code on VfnEE class. It requests "http://<ssh-hostname>/" using a HTTP library.
# async def http_check(self, id, params):
# self.logger.debug("Execute action http_check, params: '{}'".format(params))
# try:
# session = requests.Session()
# url = 'http://' + self.config_params["ssh-hostname"]
# self.logger.debug("HTTP GET {}...".format(url))
# req = session.get(url)
# self.logger.debug("{}".format(req.text))
# if req.status_code == 200:
# yield "OK", req.text
# else:
# yield "ERROR", req.text
# except Exception as e:
# self.logger.error("HTTP error: {}".format(repr(e)))
# yield "ERROR", str(e)
# This method implements the "touch" primitive. Uncomment and modify it if you need a primitive that
# imports a user-defined python library. It only needs "file" parameter for creating it in VDU via SSH.
# async def touch(self, id, params):
# self.logger.debug("Execute action touch, params: '{}'".format(params))
#
# self._check_required_params(params, ["file"])
# command = "touch" + " " + params["file"]
# return_code, description = await mylib.ssh_exec(self.config_params["ssh-hostname"], self.config_params["ssh-username"], command)
# if return_code != 0:
# yield "ERROR", description
# else:
# yield "OK", description
# This method implements the "gnbsim_up" primitive. Uncomment and modify it if you need a primitive that
# starts up the gnbsim to test 5G OAI Core. It only needs "file" parameter, in this case use gnbsim.
async def gnbsim_up(self, id, params):
self.logger.debug("Execute action gnbsim_up, params: '{}'".format(params))
self._check_required_params(params, ["file"])
command = "docker-compose -f docker-compose-gnbsim.yaml up -d" + " " + params["file"]
return_code, description = await mylib.ssh_exec(self.config_params["ssh-hostname"], self.config_params["ssh-username"], command)
if return_code != 0:
yield "ERROR", description
else:
yield "OK", description
# This method implements the "gnbsim_down" primitive. Uncomment and modify it if you need a primitive that
# stops the gnbsim for testing 5G OAI Core. It only needs "file" parameter, in this case use gnbsim.
async def gnbsim_down(self, id, params):
self.logger.debug("Execute action gnbsim_down, params: '{}'".format(params))
self._check_required_params(params, ["file"])
command = "docker-compose -f docker-compose-gnbsim.yaml down"
return_code, description = await mylib.ssh_exec(self.config_params["ssh-hostname"], self.config_params["ssh-username"], command)
if return_code != 0:
yield "ERROR", description
else:
yield "OK", description
# This method implements the "send_command" primitive. Uncomment and modify it if you need a primitive that
# sends any command to the VM through SSH. It only needs "file" parameter which contains the command to send.
async def send_command(self, id, params):
self.logger.debug("Execute action send_command, params: '{}'".format(params))
self._check_required_params(params, ["file"])
command = params["file"]
return_code, description = await mylib.ssh_exec(self.config_params["ssh-hostname"], self.config_params["ssh-username"], command)
if return_code != 0:
yield "ERROR", description
else:
yield "OK", description
# This method implements the "check_database" primitive. Uncomment and modify it if a primitive requires
# accessing to a service provided by a helm subchart. Access parameters are read from environment variables
# async def check_database(self, id, params):
# self.logger.debug("Execute action check_database, params: '{}'".format(params))
# host = os.getenv('mysql_host')
# user = os.getenv('mysql_user')
# password = os.getenv('mysql_password')
# retries = 3
# query = "SHOW DATABASES"
# return_code, description = mylib.mysql_query(host, user, password, retries, query)
# if return_code != 0:
# yield "ERROR", description
# else:
# yield "OK", description
# Static method that verifies whether a parameter exists in the map
@staticmethod
def _check_required_params(params, required_params):
for required_param in required_params:
if required_param not in params:
raise VnfException("Missing required param: {}".format(required_param))
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ . }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "eechart.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "eechart.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "eechart.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "eechart.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl port-forward $POD_NAME 8080:80
{{- end }}
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "eechart.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "eechart.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "eechart.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{/*
Common labels
*/}}
{{- define "eechart.labels" -}}
app.kubernetes.io/name: {{ include "eechart.name" . }}
helm.sh/chart: {{ include "eechart.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}
{{/*
Create the name of the service account to use
*/}}
{{- define "eechart.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "eechart.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "eechart.fullname" . }}
data:
{{ (.Files.Glob "source/*").AsConfig | indent 2 }}
apiVersion: v1
kind: ConfigMap
metadata:
name: "vnf-snmp-generator-{{ .Values.global.osm.vnf_id | lower }}"
data:
generator.yml: |-
{{ .Files.Get "snmp/generator.yml" | nindent 4}}
\ No newline at end of file
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "eechart.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
{{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1beta1
{{- else -}}
apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
{{ include "eechart.labels" . | indent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ . }}
backend:
serviceName: {{ $fullName }}
servicePort: {{ $svcPort }}
{{- end }}
{{- end }}
{{- end }}
apiVersion: v1
kind: ConfigMap
metadata:
name: "vnf-snmp-mibs-{{ .Values.global.osm.vnf_id | lower}}"
data:
{{ (.Files.Glob "snmp/mibs/**").AsConfig | indent 2 }}
\ No newline at end of file
apiVersion: v1
kind: Secret
metadata:
name: {{ include "eechart.fullname" . }}
type: Opaque
data:
mysql_host: {{ .Values.mysql.fullnameOverride | b64enc | quote }}
mysql_user: {{ "root" | b64enc | quote }}
mysql_password: {{ .Values.mysql.auth.rootPassword | b64enc | quote }}
apiVersion: v1
kind: Service
metadata:
name: {{ include "eechart.fullname" . }}
labels:
{{ include "eechart.labels" . | indent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: grpc
protocol: TCP
name: grpc
selector:
app.kubernetes.io/name: {{ include "eechart.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ template "eechart.serviceAccountName" . }}
labels:
{{ include "eechart.labels" . | indent 4 }}
{{- end -}}
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ include "eechart.fullname" . }}
labels:
{{ include "eechart.labels" . | indent 4 }}
spec:
serviceName: {{ include "eechart.fullname" . }}
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app.kubernetes.io/name: {{ include "eechart.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "eechart.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
vnf: {{ .Values.global.osm.vnf_id | lower}}
spec:
imagePullSecrets:
- name: regcred
serviceAccountName: {{ template "eechart.serviceAccountName" . }}
securityContext:
runAsUser: 0
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
envFrom:
- secretRef:
name: {{ include "eechart.fullname" . }}
ports:
- name: grpc
containerPort: 50051
protocol: TCP
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumeMounts:
- name: osm-ee
mountPath: /app/storage
- name: osm-ee-source
mountPath: /app/EE/osm_ee/vnf
- name: snmp-config-volume
mountPath: /etc/snmp_exporter
- name: vnf-mibs
mountPath: /root/.snmp/mibs
- name: vnf-generator
mountPath: /app/vnf/generator
volumes:
- name: osm-ee-source
configMap:
name: {{ include "eechart.fullname" . }}
- name: snmp-config-volume
hostPath:
path: "/var/lib/osm/snmp_exporter/{{ .Values.global.osm.vnf_id | lower }}/"
- name: vnf-mibs
configMap:
name: "vnf-snmp-mibs-{{ .Values.global.osm.vnf_id | lower}}"
- name: vnf-generator
configMap:
name: "vnf-snmp-generator-{{ .Values.global.osm.vnf_id | lower}}"
- name: osm-ee
hostPath:
path: /var/lib/osm/osm/osm_osm_packages/_data
apiVersion: v1
kind: Pod
metadata:
name: "{{ include "eechart.fullname" . }}-test-connection"
labels:
{{ include "eechart.labels" . | indent 4 }}
annotations:
"helm.sh/hook": test-success
spec:
containers:
- name: wget
image: busybox
command: ['wget']
args: ['{{ include "eechart.fullname" . }}:{{ .Values.service.port }}']
restartPolicy: Never
global:
osm:
vnf_id: AVNFId
# Default values for eechart.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
replicaCount: 1
image:
repository: opensourcemano/api-fe
tag: latest
pullPolicy: IfNotPresent
imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""
serviceAccount:
# Specifies whether a service account should be created
create: false
# The name of the service account to use.
# If not set and create is true, a name is generated using the fullname template
name:
podSecurityContext: {}
# fsGroup: 2000
securityContext: {}
# capabilities:
# drop:
# - ALL
# readOnlyRootFilesystem: true
# runAsNonRoot: true
# runAsUser: 1000
service:
type: ClusterIP
port: 50050
ingress:
enabled: false
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
hosts:
- host: chart-example.local
paths: []
tls: []
# - secretName: chart-example-tls
# hosts:
# - chart-example.local
resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi
nodeSelector: {}
tolerations: []
affinity: {}
mysql:
auth:
rootPassword: "123456"
fullnameOverride: "eechart-mysql"
# Add PDU, replace "etsi-openstack" for the name of the VIM you're using
VIMID=`osm vim-list | grep "etsi-openstack " | awk '{ print $4 }'`
sed -i "s/vim_accounts: .*/vim_accounts: [ $VIMID ]/" pdu.yaml
osm pdu-create --descriptor_file pdu.yaml
vnfd:
description: KNF with single KDU using a helm-chart for 5G OAI Core version 1.0
df:
- id: default-df
ext-cpd:
- id: mgmt-ext
k8s-cluster-net: osm-ext
id: oai_knf
k8s-cluster:
nets:
- id: osm-ext
kdu:
- name: mecplatform
helm-chart: helm-plugtest/oai-5gcore
mgmt-cp: mgmt-ext
product-name: oai_knf
provider: OAI
version: '1.0'
name: router01
description: router
type: gateway
vim_accounts: [ 42ee7fda-2996-4de0-877f-61abc792ad92 ]
shared: false
interfaces:
- name: eth0
ip-address: 172.21.250.200
mgmt: true
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment