Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions framework/python/src/net_orc/network_orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def _ci_pre_network_create(self):
""" Stores network properties to restore network after
network creation and flushes internet interface
"""

LOGGER.info('Pre network create')
self._ethmac = subprocess.check_output(
f'cat /sys/class/net/{self._session.get_internet_interface()}/address',
shell=True).decode('utf-8').strip()
Expand All @@ -295,7 +295,7 @@ def _ci_pre_network_create(self):

def _ci_post_network_create(self):
""" Restore network connection in CI environment """
LOGGER.info('post cr')
LOGGER.info('Post network create')
util.run_command(((f'ip address del {self._ipv4} ' +
'dev {self._session.get_internet_interface()}')))
util.run_command((f'ip -6 address del {self._ipv6} ' +
Expand All @@ -321,7 +321,7 @@ def _ci_post_network_create(self):
def create_net(self):
LOGGER.info('Creating baseline network')

if os.getenv('GITHUB_ACTIONS'):
if 'CI' in os.environ:
self._ci_pre_network_create()

# Setup the virtual network
Expand All @@ -330,7 +330,7 @@ def create_net(self):
self.stop()
sys.exit(1)

if os.getenv('GITHUB_ACTIONS'):
if 'CI' in os.environ:
self._ci_post_network_create()

self._create_private_net()
Expand Down
77 changes: 40 additions & 37 deletions modules/network/dhcp-1/dhcp-1.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
# Copyright 2023 Google LLC
#
# 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
#
# https://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.

# Image name: test-run/dhcp-primary
FROM test-run/base:latest

ARG MODULE_NAME=dhcp-1
ARG MODULE_DIR=modules/network/$MODULE_NAME

# Install all necessary packages
RUN apt-get update && apt-get install -y wget apt-transport-https

# Update the oui.txt file from ieee
RUN wget http://standards-oui.ieee.org/oui.txt -P /usr/local/etc/

# Install dhcp server
RUN apt-get install -y --fix-missing isc-dhcp-server radvd systemd

# Copy over all configuration files
COPY $MODULE_DIR/conf /testrun/conf

# Copy over all binary files
COPY $MODULE_DIR/bin /testrun/bin

# Copy over all python files
COPY $MODULE_DIR/python /testrun/python
# Copyright 2023 Google LLC
#
# 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
#
# https://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.

# Image name: test-run/dhcp-primary
FROM test-run/base:latest

ARG MODULE_NAME=dhcp-1
ARG MODULE_DIR=modules/network/$MODULE_NAME

#Update and get all additional requirements not contained in the base image
RUN apt-get update --fix-missing

# Install all necessary packages
RUN apt-get install -y wget

#Update the oui.txt file from ieee
RUN wget http://standards-oui.ieee.org/oui.txt -P /usr/local/etc/

# Install dhcp server
RUN apt-get install -y isc-dhcp-server radvd systemd

# Copy over all configuration files
COPY $MODULE_DIR/conf /testrun/conf

# Copy over all binary files
COPY $MODULE_DIR/bin /testrun/bin

# Copy over all python files
COPY $MODULE_DIR/python /testrun/python
77 changes: 40 additions & 37 deletions modules/network/dhcp-2/dhcp-2.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
# Copyright 2023 Google LLC
#
# 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
#
# https://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.

# Image name: test-run/dhcp-primary
FROM test-run/base:latest

ARG MODULE_NAME=dhcp-2
ARG MODULE_DIR=modules/network/$MODULE_NAME

# Install all necessary packages
RUN apt-get update && apt-get install -y wget apt-transport-https

#Update the oui.txt file from ieee
RUN wget http://standards-oui.ieee.org/oui.txt -P /usr/local/etc/

# Install dhcp server
RUN apt-get update && apt-get install -y isc-dhcp-server radvd systemd

# Copy over all configuration files
COPY $MODULE_DIR/conf /testrun/conf

# Copy over all binary files
COPY $MODULE_DIR/bin /testrun/bin

# Copy over all python files
COPY $MODULE_DIR/python /testrun/python
# Copyright 2023 Google LLC
#
# 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
#
# https://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.

# Image name: test-run/dhcp-primary
FROM test-run/base:latest

ARG MODULE_NAME=dhcp-2
ARG MODULE_DIR=modules/network/$MODULE_NAME

#Update and get all additional requirements not contained in the base image
RUN apt-get update --fix-missing

# Install all necessary packages
RUN apt-get install -y wget

#Update the oui.txt file from ieee
RUN wget http://standards-oui.ieee.org/oui.txt -P /usr/local/etc/

# Install dhcp server
RUN apt-get install -y isc-dhcp-server radvd systemd

# Copy over all configuration files
COPY $MODULE_DIR/conf /testrun/conf

# Copy over all binary files
COPY $MODULE_DIR/bin /testrun/bin

# Copy over all python files
COPY $MODULE_DIR/python /testrun/python
6 changes: 6 additions & 0 deletions modules/network/ntp/bin/start_network_service
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ LOG_FILE="/runtime/network/ntp.log"

echo Starting ntp

# Route internet traffic through gateway
ip route add default via 10.10.10.1 dev veth0

#Create and set permissions on the log file
touch $LOG_FILE
chown $HOST_USER $LOG_FILE

# Move the config files to the correct location
cp /testrun/conf/chrony.conf /etc/chrony/

#Start the NTP server
python3 -u $PYTHON_SRC_DIR/ntp_server.py > $LOG_FILE
62 changes: 62 additions & 0 deletions modules/network/ntp/conf/chrony.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Welcome to the chrony configuration file. See chrony.conf(5) for more
# information about usable directives.

# Include configuration files found in /etc/chrony/conf.d.
confdir /etc/chrony/conf.d

# This will use (up to):
# - 4 sources from ntp.ubuntu.com which some are ipv6 enabled
# - 2 sources from 2.ubuntu.pool.ntp.org which is ipv6 enabled as well
# - 1 source from [01].ubuntu.pool.ntp.org each (ipv4 only atm)
# This means by default, up to 6 dual-stack and up to 2 additional IPv4-only
# sources will be used.
# At the same time it retains some protection against one of the entries being
# down (compare to just using one of the lines). See (LP: #1754358) for the
# discussion.
#
# About using servers from the NTP Pool Project in general see (LP: #104525).
# Approved by Ubuntu Technical Board on 2011-02-08.
# See http://www.pool.ntp.org/join.html for more information.
pool time.google.com iburst maxsources 4

# Use time sources from DHCP.
sourcedir /run/chrony-dhcp

# Use NTP sources found in /etc/chrony/sources.d.
sourcedir /etc/chrony/sources.d

# This directive specify the location of the file containing ID/key pairs for
# NTP authentication.
keyfile /etc/chrony/chrony.keys

# This directive0 specify the file into which chronyd will store the rate
# information.
driftfile /var/lib/chrony/chrony.drift

# Save NTS keys and cookies.
ntsdumpdir /var/lib/chrony

# Uncomment the following line to turn logging on.
#log tracking measurements statistics

# Log files location.
logdir /var/log/chrony

# Stop bad estimates upsetting machine clock.
maxupdateskew 100.0

# This directive enables kernel synchronisation (every 11 minutes) of the
# real-time clock. Note that it can’t be used along with the 'rtcfile' directive.
rtcsync

# Step the system clock instead of slewing it if the adjustment is larger than
# one second, but only in the first three clock updates.
makestep 1 3

# Get TAI-UTC offset and leap seconds from the system tz database.
# This directive must be commented out when using time sources serving
# leap-smeared time.
leapsectz right/UTC

# Enable NTP server and allow all traffic to this server
allow
66 changes: 36 additions & 30 deletions modules/network/ntp/ntp.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
# Copyright 2023 Google LLC
#
# 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
#
# https://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.

# Image name: test-run/ntp
FROM test-run/base:latest

ARG MODULE_NAME=ntp
ARG MODULE_DIR=modules/network/$MODULE_NAME

# Copy over all configuration files
COPY $MODULE_DIR/conf /testrun/conf

# Copy over all binary files
COPY $MODULE_DIR/bin /testrun/bin

# Copy over all python files
COPY $MODULE_DIR/python /testrun/python

EXPOSE 123/udp
# Copyright 2023 Google LLC
#
# 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
#
# https://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.

# Image name: test-run/ntp
FROM test-run/base:latest

ARG MODULE_NAME=ntp
ARG MODULE_DIR=modules/network/$MODULE_NAME

# Set DEBIAN_FRONTEND to noninteractive mode
ENV DEBIAN_FRONTEND=noninteractive

# Install all necessary packages
RUN apt-get install -y chrony

# Copy over all configuration files
COPY $MODULE_DIR/conf /testrun/conf

# Copy over all binary files
COPY $MODULE_DIR/bin /testrun/bin

# Copy over all python files
COPY $MODULE_DIR/python /testrun/python

EXPOSE 123/udp
49 changes: 49 additions & 0 deletions modules/network/ntp/python/src/chronyd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright 2023 Google LLC
#
# 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
#
# https://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.
"""Contains all the necessary classes to maintain the
chronyd server booted from the chronyd.conf file"""
from common import logger
from common import util
import os

LOG_NAME = 'chronyd'
LOGGER = None
PID_FILE='/run/chrony/chronyd.pid'

class ChronydServer:
"""Represents the chronyd server"""

def __init__(self):
global LOGGER
LOGGER = logger.get_logger(LOG_NAME, 'ntp')

def start(self):
LOGGER.info('Starting chronyd server')
response = util.run_command('chronyd', False)
LOGGER.info('chronyd server started: ' + str(response))
return response

def stop(self):
LOGGER.info('Stopping chronyd server')
with open(PID_FILE, 'r', encoding='UTF-8') as f:
pid = f.read()
response = util.run_command(f'kill {pid}', False)
LOGGER.info('chronyd server stopped: ' + str(response))
return response

def is_running(self):
LOGGER.info('Checking chronyd server')
running = os.path.exists(PID_FILE)
LOGGER.info('chronyd server status: ' + str(running))
return running
Loading