Commit ef683b47 authored by Lu Xu's avatar Lu Xu 👀

software/ors-amarisoft: add reset function for RRH

parent 9a73bee4
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
[template] [template]
filename = instance.cfg filename = instance.cfg
md5sum = bc60058a9407fc481b1a652b2f3b5498 md5sum = 998b5ec0dc8c76736c624af2f96ea94d
[amarisoft-stats.jinja2.py] [amarisoft-stats.jinja2.py]
_update_hash_filename_ = amarisoft-stats.jinja2.py _update_hash_filename_ = amarisoft-stats.jinja2.py
...@@ -28,7 +28,7 @@ md5sum = ab666fdfadbfc7d8a16ace38d295c883 ...@@ -28,7 +28,7 @@ md5sum = ab666fdfadbfc7d8a16ace38d295c883
[ncclient_common] [ncclient_common]
_update_hash_filename_ = ncclient_common.py _update_hash_filename_ = ncclient_common.py
md5sum = 63316f6a8a6a480e10db7e78cca72f3b md5sum = 6f8d0592cc4b0b695cea5a0c25aafc4e
[lopcomm-rrh-stats.jinja2.py] [lopcomm-rrh-stats.jinja2.py]
_update_hash_filename_ = lopcomm-rrh-stats.jinja2.py _update_hash_filename_ = lopcomm-rrh-stats.jinja2.py
...@@ -46,9 +46,17 @@ md5sum = 2cd8515253b75e2ab13cc77399762851 ...@@ -46,9 +46,17 @@ md5sum = 2cd8515253b75e2ab13cc77399762851
_update_hash_filename_ = lopcomm-rrh-supervision.jinja2.py _update_hash_filename_ = lopcomm-rrh-supervision.jinja2.py
md5sum = 243d9fbf640b8dc8bf63d69b07b8afed md5sum = 243d9fbf640b8dc8bf63d69b07b8afed
[lopcomm-rrh-reset-info.jinja2.py]
_update_hash_filename_ = lopcomm-rrh-reset-info.jinja2.py
md5sum = e03d7fea24566aa8291f0dc4aaf09c67
[lopcomm-rrh-reset.jinja2.py]
_update_hash_filename_ = lopcomm-rrh-reset.jinja2.py
md5sum = 63472d5dc9bd46923d3941b5189e2ccd
[template-enb] [template-enb]
_update_hash_filename_ = instance-enb.jinja2.cfg _update_hash_filename_ = instance-enb.jinja2.cfg
md5sum = 8a47df7cfefa3876afea38ced2c5005f md5sum = 0d6843d49d5e141378006add136a554b
[template-gnb] [template-gnb]
_update_hash_filename_ = instance-gnb.jinja2.cfg _update_hash_filename_ = instance-gnb.jinja2.cfg
......
...@@ -240,6 +240,11 @@ ...@@ -240,6 +240,11 @@
"textarea": true, "textarea": true,
"type": "string" "type": "string"
}, },
"cron_schedule": {
"title": "Cron schedule for RRH reset",
"description": "Refer https://crontab.guru/ to make a reset schedule for RRH, for example, '0 1 * * *' means the RRH will reset every day at 1 am",
"type": "string"
},
{%- endif %} {%- endif %}
"enb_id": { "enb_id": {
"title": "eNB ID", "title": "eNB ID",
......
...@@ -14,6 +14,10 @@ parts = ...@@ -14,6 +14,10 @@ parts =
lopcomm-firmware-dl lopcomm-firmware-dl
lopcomm-rrh-stats-service lopcomm-rrh-stats-service
lopcomm-rrh-supervision-service lopcomm-rrh-supervision-service
lopcomm-rrh-reset-info-service
{% if slapparameter_dict.get("cron_schedule", None) %}
lopcomm-rrh-reset-cron
{% endif %}
lopcomm-rrh-config-template lopcomm-rrh-config-template
lopcomm-rrh-software-template lopcomm-rrh-software-template
netconf-connection-promise netconf-connection-promise
...@@ -369,6 +373,45 @@ mode = 0775 ...@@ -369,6 +373,45 @@ mode = 0775
url = {{ lopcomm_rrh_supervision_template }} url = {{ lopcomm_rrh_supervision_template }}
output = ${directory:bin}/lopcomm-rrh-supervision.py output = ${directory:bin}/lopcomm-rrh-supervision.py
[lopcomm-rrh-reset-info-template]
recipe = slapos.recipe.template:jinja2
extensions = jinja2.ext.do
log-output = ${directory:var}/log/lopcomm-rrh-reset-info.log
json-log-output = ${directory:var}/log/lopcomm-rrh-reset-info.json.log
context =
section slap_configuration slap-configuration
key log_file :log-output
key json_log_file :json-log-output
raw stats_period {{ slapparameter_dict.get("enb_stats_fetch_period", 60) }}
raw testing {{ slapparameter_dict.get("testing", False) }}
raw python_path {{ buildout_directory}}/bin/pythonwitheggs
import netaddr netaddr
mode = 0775
url = {{ lopcomm_rrh_reset_info_template }}
output = ${directory:bin}/lopcomm-rrh-reset-info.py
[lopcomm-rrh-reset-template]
recipe = slapos.recipe.template:jinja2
extensions = jinja2.ext.do
log-output = ${directory:var}/log/lopcomm-rrh-reset.log
json-log-output = ${directory:var}/log/lopcomm-rrh-reset.json.log
context =
section slap_configuration slap-configuration
key log_file :log-output
raw python_path {{ buildout_directory}}/bin/pythonwitheggs
raw buildout_directory_path {{ buildout_directory }}
import netaddr netaddr
mode = 0775
url = {{ lopcomm_rrh_reset_template }}
output = ${directory:etc}/lopcomm-rrh-reset.py
[lopcomm-rrh-reset-cron]
recipe = slapos.cookbook:cron.d
cron-entries = ${cron:cron-entries}
name = rrh-resest
frequency = {{ slapparameter_dict.get("cron_schedule", "") }}
command = {{ buildout_directory}}/bin/pythonwitheggs ${lopcomm-rrh-reset-template:output}
[netconf-connection-promise] [netconf-connection-promise]
<= monitor-promise-base <= monitor-promise-base
promise = check_command_execute promise = check_command_execute
...@@ -420,6 +463,14 @@ mode = 0775 ...@@ -420,6 +463,14 @@ mode = 0775
hash-files = hash-files =
${lopcomm-rrh-supervision-template:output} ${lopcomm-rrh-supervision-template:output}
[lopcomm-rrh-reset-info-service]
recipe = slapos.cookbook:wrapper
command-line = ${lopcomm-rrh-reset-info-template:output}
wrapper-path = ${directory:service}/lopcomm-rrh-reset-info
mode = 0775
hash-files =
${lopcomm-rrh-reset-info-template:output}
[lopcomm-firmware-dl] [lopcomm-firmware-dl]
recipe = slapos.recipe.build:download recipe = slapos.recipe.build:download
url = https://lab.nexedi.com/nexedi/ors-utils/raw/master/lopcomm-firmware/${:filename} url = https://lab.nexedi.com/nexedi/ors-utils/raw/master/lopcomm-firmware/${:filename}
...@@ -545,6 +596,8 @@ monitor-gadget-url = ${:monitor-base-url}/gadget/software.cfg.html ...@@ -545,6 +596,8 @@ monitor-gadget-url = ${:monitor-base-url}/gadget/software.cfg.html
{% if ru == "lopcomm" %} {% if ru == "lopcomm" %}
ssh-command = ssh ${user-info:pw-name}@${slap-configuration:ipv6-random} -p ${sshd-port:port} ssh-command = ssh ${user-info:pw-name}@${slap-configuration:ipv6-random} -p ${sshd-port:port}
ssh-url = ssh://${user-info:pw-name}@[${slap-configuration:ipv6-random}]:${sshd-port:port} ssh-url = ssh://${user-info:pw-name}@[${slap-configuration:ipv6-random}]:${sshd-port:port}
ru-firmware = ${lopcomm-firmware-dl:filename}
ru-ipv6 = ${slap-configuration:tap-ipv6-gateway}
{% endif %} {% endif %}
[monitor-instance-parameter] [monitor-instance-parameter]
......
...@@ -167,6 +167,11 @@ ...@@ -167,6 +167,11 @@
"textarea": true, "textarea": true,
"type": "string" "type": "string"
}, },
"cron_schedule": {
"title": "Cron schedule for RRH reset",
"description": "Refer https://crontab.guru/ to make a reset schedule for RRH, for example, '0 1 * * *' means the RRH will reset every day at 1 am",
"type": "string"
},
"enb_id": { "enb_id": {
"title": "eNB ID", "title": "eNB ID",
"description": "eNB ID", "description": "eNB ID",
......
...@@ -258,6 +258,8 @@ extra-context = ...@@ -258,6 +258,8 @@ extra-context =
raw lopcomm_rrh_config_template ${lopcomm-rrh-config.jinja2.py:target} raw lopcomm_rrh_config_template ${lopcomm-rrh-config.jinja2.py:target}
raw lopcomm_rrh_software_template ${lopcomm-rrh-software.jinja2.py:target} raw lopcomm_rrh_software_template ${lopcomm-rrh-software.jinja2.py:target}
raw lopcomm_rrh_supervision_template ${lopcomm-rrh-supervision.jinja2.py:target} raw lopcomm_rrh_supervision_template ${lopcomm-rrh-supervision.jinja2.py:target}
raw lopcomm_rrh_reset_info_template ${lopcomm-rrh-reset-info.jinja2.py:target}
raw lopcomm_rrh_reset_template ${lopcomm-rrh-reset.jinja2.py:target}
raw CreateProcessingEle_template ${CreateProcessingEle.jinja2.xml:target} raw CreateProcessingEle_template ${CreateProcessingEle.jinja2.xml:target}
raw cu_config_template ${cu_config.jinja2.xml:target} raw cu_config_template ${cu_config.jinja2.xml:target}
raw openssl_location ${openssl:location} raw openssl_location ${openssl:location}
......
#!{{ python_path }}
import paramiko
import logging
from logging.handlers import RotatingFileHandler
def get_uptime(hostname, username, password):
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
client.connect(hostname, username=username, password=password)
stdin, stdout, stderr = client.exec_command('uptime')
uptime_output = stdout.read().decode()
return uptime_output
except Exception as e:
logger.info(f"Error: {e}")
finally:
client.close()
# Usage
hostname = "{{ netaddr.IPAddress(slap_configuration.get('tap-ipv6-gateway', '')) }}"
username = "oranuser"
password = "oranpassword"
# Initialize logger
log_file = "{{ log_file }}"
logger = logging.getLogger('logger')
logger.setLevel(logging.INFO)
handler = RotatingFileHandler(log_file, maxBytes=30000, backupCount=2)
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
if {{ testing }}:
pass
else:
rrh_uptime = get_uptime(hostname, username, password)
logger.info(f"Uptime from RRH: {rrh_uptime}")
...@@ -5,15 +5,13 @@ sys.path.append({{ repr(buildout_directory_path) }}) ...@@ -5,15 +5,13 @@ sys.path.append({{ repr(buildout_directory_path) }})
from ncclient_common import LopcommNetconfClient from ncclient_common import LopcommNetconfClient
if __name__ == '__main__': if __name__ == '__main__':
nc = LopcommNetconfClient(log_file="{{ log_file }}") nc = LopcommNetconfClient(log_file="{{ log_file }}")
while True: try:
try: nc.connect("{{ netaddr.IPAddress(slap_configuration.get('tap-ipv6-gateway', '')) }}", 830, "oranuser", "oranpassword")
nc.connect("{{ netaddr.IPAddress(slap_configuration.get('tap-ipv6-gateway', '')) }}", 830, "oranuser", "oranpassword") nc.reset_device()
nc.nc.reset_device() nc.logger.info("Device reset successful.")
break except Exception as e:
except Exception as e: nc.logger.debug('Got exception while resetting...')
nc.logger.debug('Got exception, waiting 10 seconds before reconnecting...') nc.logger.debug(e)
nc.logger.debug(e) finally:
time.sleep(10) nc.close()
finally:
nc.close()
...@@ -153,7 +153,8 @@ class LopcommNetconfClient: ...@@ -153,7 +153,8 @@ class LopcommNetconfClient:
reset_reply_xml = self.custom_rpc_request(reset_rpc_xml) reset_reply_xml = self.custom_rpc_request(reset_rpc_xml)
if reset_reply_xml: if reset_reply_xml:
reset_data = xmltodict.parse(reset_reply_xml) reset_data = xmltodict.parse(reset_reply_xml)
self.software_reply_json_logger.info('', extra={'data': json.dumps(reset_data)}) if self.software_reply_json_logger:
self.software_reply_json_logger.info('', extra={'data': json.dumps(reset_data)})
self.logger.info('Wait 60 second then reboot!') self.logger.info('Wait 60 second then reboot!')
time.sleep(60) time.sleep(60)
......
...@@ -80,6 +80,12 @@ destination = ${buildout:directory}/ncclient_common.py ...@@ -80,6 +80,12 @@ destination = ${buildout:directory}/ncclient_common.py
[lopcomm-rrh-supervision.jinja2.py] [lopcomm-rrh-supervision.jinja2.py]
<= download-base <= download-base
[lopcomm-rrh-reset-info.jinja2.py]
<= download-base
[lopcomm-rrh-reset.jinja2.py]
<= download-base
[template-enb] [template-enb]
<= download-base <= download-base
......
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