Skip to content

Commit 2aa5926

Browse files
authored
Merge pull request #3364 from Azure/release-2.13.1.0
Release 2.13.1.1 (branch release-2.13.1.0) to master
2 parents c4d421e + 9caca60 commit 2aa5926

File tree

138 files changed

+6803
-3691
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+6803
-3691
lines changed

.github/workflows/ci_pr.yml

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
name: "Python ${{ matrix.python-version }} Unit Tests"
2121
runs-on: ubuntu-20.04
2222
container:
23-
image: ubuntu:16.04
23+
image: ubuntu:24.04
2424
volumes:
2525
- /home/waagent:/home/waagent
2626
defaults:
@@ -29,25 +29,32 @@ jobs:
2929

3030
env:
3131
NOSEOPTS: "--verbose"
32-
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
33-
32+
3433
steps:
3534
- uses: actions/checkout@v3
3635

37-
- name: Install Python ${{ matrix.python-version }}
36+
- name: Install Python ${{ matrix.python-version }} Virtual Environment
3837
run: |
3938
apt-get update
40-
apt-get install -y curl bzip2 sudo python3
41-
curl https://dcrdata.blob.core.windows.net/python/python-${{ matrix.python-version }}.tar.bz2 -o python-${{ matrix.python-version }}.tar.bz2
42-
sudo tar xjvf python-${{ matrix.python-version }}.tar.bz2 --directory /
39+
apt-get install -y curl bzip2 sudo
40+
curl -sSf --retry 5 -o /tmp/python-${{ matrix.python-version }}.tar.bz2 https://dcrdata.blob.core.windows.net/python/python-${{ matrix.python-version }}.tar.bz2
41+
sudo tar xjf /tmp/python-${{ matrix.python-version }}.tar.bz2 --directory /
42+
#
43+
# TODO: Some unit tests create helper scripts that use 'python3' as shebang; we should probably port them to Bash, but installing Python 3 as a workaround for now.
44+
#
45+
if [[ "${{ matrix.python-version }}" == "2.6" ]]; then
46+
apt-get -y install python3
47+
fi
48+
#
49+
# The virtual environments for 2.6 and 3.4 have dependencies on OpenSSL 1.0, which is not available beyond Ubuntu 16. We use this script to patch the environments.
50+
#
51+
if [[ "${{ matrix.python-version }}" =~ ^2\.6|3\.4$ ]]; then
52+
./tests/python_eol/patch_python_venv.sh "${{ matrix.python-version }}"
53+
fi
4354
44-
- name: Test with nosetests
55+
- name: Execute Tests
4556
run: |
46-
if [[ ${{ matrix.python-version }} == "2.6" ]]; then
47-
source /home/waagent/virtualenv/python2.6.9/bin/activate
48-
else
49-
source /home/waagent/virtualenv/python3.4.8/bin/activate
50-
fi
57+
source /home/waagent/virtualenv/python${{ matrix.python-version }}/bin/activate
5158
./ci/nosetests.sh
5259
exit $?
5360

azurelinuxagent/agent.py

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,18 @@
3434
from azurelinuxagent.ga import logcollector, cgroupconfigurator
3535
from azurelinuxagent.ga.cgroupcontroller import AGENT_LOG_COLLECTOR
3636
from azurelinuxagent.ga.cpucontroller import _CpuController
37-
from azurelinuxagent.ga.cgroupapi import get_cgroup_api, log_cgroup_warning, InvalidCgroupMountpointException
37+
from azurelinuxagent.ga.cgroupapi import create_cgroup_api, InvalidCgroupMountpointException
38+
from azurelinuxagent.ga.firewall_manager import FirewallManager
3839

3940
import azurelinuxagent.common.conf as conf
4041
import azurelinuxagent.common.event as event
4142
import azurelinuxagent.common.logger as logger
43+
from azurelinuxagent.common.event import WALAEventOperation
4244
from azurelinuxagent.common.future import ustr
4345
from azurelinuxagent.ga.logcollector import LogCollector, OUTPUT_RESULTS_FILE_PATH
4446
from azurelinuxagent.common.osutil import get_osutil
4547
from azurelinuxagent.common.utils import fileutil, textutil
4648
from azurelinuxagent.common.utils.flexible_version import FlexibleVersion
47-
from azurelinuxagent.common.utils.networkutil import AddFirewallRules
4849
from azurelinuxagent.common.version import AGENT_NAME, AGENT_LONG_VERSION, AGENT_VERSION, \
4950
DISTRO_NAME, DISTRO_VERSION, \
5051
PY_VERSION_MAJOR, PY_VERSION_MINOR, \
@@ -208,28 +209,34 @@ def collect_logs(self, is_full_mode):
208209
else:
209210
logger.info("Running log collector mode normal")
210211

212+
LogCollector.initialize_telemetry()
213+
211214
# Check the cgroups unit
212215
log_collector_monitor = None
213216
tracked_controllers = []
214217
if CollectLogsHandler.is_enabled_monitor_cgroups_check():
215218
try:
216-
cgroup_api = get_cgroup_api()
219+
cgroup_api = create_cgroup_api()
220+
logger.info("Using cgroup {0} for resource enforcement and monitoring".format(cgroup_api.get_cgroup_version()))
217221
except InvalidCgroupMountpointException as e:
218-
log_cgroup_warning("The agent does not support cgroups if the default systemd mountpoint is not being used: {0}".format(ustr(e)), send_event=True)
222+
event.warn(WALAEventOperation.LogCollection, "The agent does not support cgroups if the default systemd mountpoint is not being used: {0}", ustr(e))
219223
sys.exit(logcollector.INVALID_CGROUPS_ERRCODE)
220224
except CGroupsException as e:
221-
log_cgroup_warning("Unable to determine which cgroup version to use: {0}".format(ustr(e)), send_event=True)
225+
event.warn(WALAEventOperation.LogCollection, "Unable to determine which cgroup version to use: {0}", ustr(e))
222226
sys.exit(logcollector.INVALID_CGROUPS_ERRCODE)
223227

224228
log_collector_cgroup = cgroup_api.get_process_cgroup(process_id="self", cgroup_name=AGENT_LOG_COLLECTOR)
225229
tracked_controllers = log_collector_cgroup.get_controllers()
230+
for controller in tracked_controllers:
231+
logger.info("{0} controller for cgroup: {1}".format(controller.get_controller_type(), controller))
226232

227233
if len(tracked_controllers) != len(log_collector_cgroup.get_supported_controller_names()):
228-
log_cgroup_warning("At least one required controller is missing. The following controllers are required for the log collector to run: {0}".format(log_collector_cgroup.get_supported_controller_names()))
234+
event.warn(WALAEventOperation.LogCollection, "At least one required controller is missing. The following controllers are required for the log collector to run: {0}", log_collector_cgroup.get_supported_controller_names())
229235
sys.exit(logcollector.INVALID_CGROUPS_ERRCODE)
230236

231-
if not log_collector_cgroup.check_in_expected_slice(cgroupconfigurator.LOGCOLLECTOR_SLICE):
232-
log_cgroup_warning("The Log Collector process is not in the proper cgroups", send_event=False)
237+
expected_slice = cgroupconfigurator.LOGCOLLECTOR_SLICE
238+
if not log_collector_cgroup.check_in_expected_slice(expected_slice):
239+
event.warn(WALAEventOperation.LogCollection, "The Log Collector process is not in the proper cgroups. Expected slice: {0}", expected_slice)
233240
sys.exit(logcollector.INVALID_CGROUPS_ERRCODE)
234241

235242
try:
@@ -270,15 +277,16 @@ def collect_logs(self, is_full_mode):
270277
log_collector_monitor.stop()
271278

272279
@staticmethod
273-
def setup_firewall(firewall_metadata):
274-
275-
print("Setting up firewall for the WALinux Agent with args: {0}".format(firewall_metadata))
280+
def setup_firewall(endpoint):
281+
logger.set_prefix("Firewall")
282+
threading.current_thread().name = "Firewall"
283+
event.info(event.WALAEventOperation.Firewall, "Setting up firewall after boot. Endpoint: {0}", ustr(endpoint))
276284
try:
277-
AddFirewallRules.add_iptables_rules(firewall_metadata['wait'], firewall_metadata['dst_ip'],
278-
firewall_metadata['uid'])
279-
print("Successfully set the firewall rules")
285+
firewall_manager = FirewallManager.create(endpoint)
286+
firewall_manager.setup()
287+
event.info(event.WALAEventOperation.Firewall, "Successfully set the firewall rules")
280288
except Exception as error:
281-
print("Unable to add firewall rules. Error: {0}".format(ustr(error)))
289+
event.error(event.WALAEventOperation.Firewall, "Unable to add firewall rules. Error: {0}", ustr(error))
282290
sys.exit(1)
283291

284292

@@ -291,7 +299,7 @@ def main(args=None):
291299
args = []
292300
if len(args) <= 0:
293301
args = sys.argv[1:]
294-
command, force, verbose, debug, conf_file_path, log_collector_full_mode, firewall_metadata = parse_args(args)
302+
command, force, verbose, debug, conf_file_path, log_collector_full_mode, firewall_endpoint = parse_args(args)
295303
if command == AgentCommands.Version:
296304
version()
297305
elif command == AgentCommands.Help:
@@ -318,7 +326,7 @@ def main(args=None):
318326
elif command == AgentCommands.CollectLogs:
319327
agent.collect_logs(log_collector_full_mode)
320328
elif command == AgentCommands.SetupFirewall:
321-
agent.setup_firewall(firewall_metadata)
329+
agent.setup_firewall(firewall_endpoint)
322330
except Exception as e:
323331
logger.error(u"Failed to run '{0}': {1}",
324332
command,
@@ -335,11 +343,7 @@ def parse_args(sys_args):
335343
debug = False
336344
conf_file_path = None
337345
log_collector_full_mode = False
338-
firewall_metadata = {
339-
"dst_ip": None,
340-
"uid": None,
341-
"wait": ""
342-
}
346+
endpoint = None
343347

344348
regex_cmd_format = "^([-/]*){0}"
345349

@@ -383,20 +387,17 @@ def parse_args(sys_args):
383387
cmd = AgentCommands.CollectLogs
384388
elif re.match(regex_cmd_format.format("full"), arg):
385389
log_collector_full_mode = True
386-
elif re.match(regex_cmd_format.format(AgentCommands.SetupFirewall), arg):
387-
cmd = AgentCommands.SetupFirewall
388-
elif re.match(regex_cmd_format.format("dst_ip=(?P<dst_ip>[\\d.]{7,})"), arg):
389-
firewall_metadata['dst_ip'] = re.match(regex_cmd_format.format("dst_ip=(?P<dst_ip>[\\d.]{7,})"), arg).group(
390-
'dst_ip')
391-
elif re.match(regex_cmd_format.format("uid=(?P<uid>[\\d]+)"), arg):
392-
firewall_metadata['uid'] = re.match(regex_cmd_format.format("uid=(?P<uid>[\\d]+)"), arg).group('uid')
393-
elif re.match(regex_cmd_format.format("(w|wait)$"), arg):
394-
firewall_metadata['wait'] = "-w"
395390
else:
396-
cmd = AgentCommands.Help
397-
break
391+
regex_cmd = regex_cmd_format.format("{0}=(?P<endpoint>[\\d.]{{7,}})".format(AgentCommands.SetupFirewall))
392+
match = re.match(regex_cmd, arg)
393+
if match is not None:
394+
cmd = AgentCommands.SetupFirewall
395+
endpoint = match.group('endpoint')
396+
else:
397+
cmd = AgentCommands.Help
398+
break
398399

399-
return cmd, force, verbose, debug, conf_file_path, log_collector_full_mode, firewall_metadata
400+
return cmd, force, verbose, debug, conf_file_path, log_collector_full_mode, endpoint
400401

401402

402403
def version():
@@ -416,11 +417,11 @@ def usage():
416417
"""
417418
Return agent usage message
418419
"""
419-
s = "\n"
420+
s = "\n"
420421
s += ("usage: {0} [-verbose] [-force] [-help] "
421422
"-configuration-path:<path to configuration file>"
422423
"-deprovision[+user]|-register-service|-version|-daemon|-start|"
423-
"-run-exthandlers|-show-configuration|-collect-logs [-full]|-setup-firewall [-dst_ip=<IP> -uid=<UID> [-w/--wait]]"
424+
"-run-exthandlers|-show-configuration|-collect-logs [-full]|-setup-firewall=<IP>]"
424425
"").format(sys.argv[0])
425426
s += "\n"
426427
return s

azurelinuxagent/common/conf.py

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ def load_conf_from_file(conf_file_path, conf=__conf__):
147147
"Debug.EnableAgentMemoryUsageCheck": False,
148148
"Debug.EnableFastTrack": True,
149149
"Debug.EnableGAVersioning": True,
150-
"Debug.EnableCgroupV2ResourceLimiting": False
150+
"Debug.EnableCgroupV2ResourceLimiting": False,
151+
"Debug.EnableExtensionPolicy": False
151152
}
152153

153154

@@ -170,8 +171,7 @@ def load_conf_from_file(conf_file_path, conf=__conf__):
170171
"ResourceDisk.MountOptions": None,
171172
"ResourceDisk.Filesystem": "ext3",
172173
"AutoUpdate.GAFamily": "Prod",
173-
"Debug.CgroupMonitorExpiryTime": "2022-03-31",
174-
"Debug.CgroupMonitorExtensionName": "Microsoft.Azure.Monitor.AzureMonitorLinuxAgent",
174+
"Policy.PolicyFilePath": "/etc/waagent_policy.json"
175175
}
176176

177177

@@ -316,6 +316,10 @@ def get_agent_log_file():
316316
return "/var/log/waagent.log"
317317

318318

319+
def get_policy_file_path(conf=__conf__):
320+
return conf.get("Policy.PolicyFilePath", "/etc/waagent_policy.json")
321+
322+
319323
def get_fips_enabled(conf=__conf__):
320324
return conf.get_switch("OS.EnableFIPS", False)
321325

@@ -615,25 +619,6 @@ def get_enable_agent_memory_usage_check(conf=__conf__):
615619
"""
616620
return conf.get_switch("Debug.EnableAgentMemoryUsageCheck", False)
617621

618-
619-
def get_cgroup_monitor_expiry_time(conf=__conf__):
620-
"""
621-
cgroups monitoring for pilot extensions disabled after expiry time
622-
623-
NOTE: This option is experimental and may be removed in later versions of the Agent.
624-
"""
625-
return conf.get("Debug.CgroupMonitorExpiryTime", "2022-03-31")
626-
627-
628-
def get_cgroup_monitor_extension_name (conf=__conf__):
629-
"""
630-
cgroups monitoring extension name
631-
632-
NOTE: This option is experimental and may be removed in later versions of the Agent.
633-
"""
634-
return conf.get("Debug.CgroupMonitorExtensionName", "Microsoft.Azure.Monitor.AzureMonitorLinuxAgent")
635-
636-
637622
def get_enable_fast_track(conf=__conf__):
638623
"""
639624
If True, the agent use FastTrack when retrieving goal states
@@ -683,13 +668,21 @@ def get_firewall_rules_log_period(conf=__conf__):
683668
"""
684669
return conf.get_int("Debug.FirewallRulesLogPeriod", 86400)
685670

671+
672+
def get_extension_policy_enabled(conf=__conf__):
673+
"""
674+
Determine whether extension policy is enabled. If true, policy will be enforced before installing any extensions.
675+
NOTE: This option is experimental and may be removed in later versions of the Agent.
676+
"""
677+
return conf.get_switch("Debug.EnableExtensionPolicy", False)
686678

679+
687680
def get_enable_cgroup_v2_resource_limiting(conf=__conf__):
688681
"""
689682
If True, the agent will enable resource monitoring and enforcement for the log collector on machines using cgroup v2.
690683
NOTE: This option is experimental and may be removed in later versions of the Agent.
691684
"""
692-
return conf.get_switch("Debug.EnableCgroupV2ResourceLimiting", False)
685+
return conf.get_switch("Debug.EnableCgroupV2ResourceLimiting", True)
693686

694687

695688
def get_log_collector_initial_delay(conf=__conf__):

0 commit comments

Comments
 (0)