Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove file dependency #1754

Merged
merged 25 commits into from
Jan 15, 2020
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3684207
Made GS private and removed dependency on filesystem
larohra Jan 8, 2020
3f11615
Made shared_conf, hosting_env and certs private and removed cache dep…
larohra Jan 9, 2020
158be2b
Made all wireclient properties private and created relevant setters f…
larohra Jan 9, 2020
b36ee8b
Removed dependency on Incarnation file too
larohra Jan 9, 2020
fd3f8a1
Removed type hints from code
larohra Jan 9, 2020
23fdbcf
Raising ProtocolError if object not defined and updated HostPlugin api
larohra Jan 9, 2020
ffbd1cf
Made GS private and removed dependency on filesystem
larohra Jan 8, 2020
61634b2
Made shared_conf, hosting_env and certs private and removed cache dep…
larohra Jan 9, 2020
3e39a70
Made all wireclient properties private and created relevant setters f…
larohra Jan 9, 2020
7cec53f
Removed dependency on Incarnation file too
larohra Jan 9, 2020
3a15ff7
Removed type hints from code
larohra Jan 9, 2020
57cc85c
Raising ProtocolError if object not defined and updated HostPlugin api
larohra Jan 9, 2020
0491d61
Merge branch 'RemoveFileDependency' of https://github.com/larohra/WAL…
larohra Jan 9, 2020
0a4ba05
Keeping the original behaviour just without the file system
larohra Jan 9, 2020
e56a58d
Updated failing test cases
larohra Jan 10, 2020
82fad0f
Removed type hints
larohra Jan 10, 2020
e34a1d5
Removed dependency on Incarnation File
larohra Jan 10, 2020
43ab21b
Made wireclient endpoint private
larohra Jan 10, 2020
3db1d94
Merge branch 'develop' into RemoveFileDependency
larohra Jan 10, 2020
bfdd5e7
Fix failing tests after merge
larohra Jan 10, 2020
7923262
Removed unnecessary comments and cleaned up code
larohra Jan 11, 2020
33ccba8
Removed the AgentManifestFileName file as the usage was redundant; ad…
larohra Jan 13, 2020
5f4d76f
Made SharedConfig.parse function private and consistent with other ob…
larohra Jan 13, 2020
e38e9df
Addressed PR comments and removed extra logging, reverted back RDMA code
larohra Jan 15, 2020
68cf77b
Not raising ProtocolError in getters where the property can be None a…
larohra Jan 15, 2020
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
9 changes: 9 additions & 0 deletions azurelinuxagent/common/protocol/hostplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ def is_default_channel():
def set_default_channel(is_default):
HostPluginProtocol._is_default_channel = is_default

def update_container_id(self, new_container_id):
self.container_id = new_container_id

def update_role_config_name(self, new_role_config_name):
self.role_config_name = new_role_config_name

def update_manifest_uri(self, new_manifest_uri):
self.manifest_uri = new_manifest_uri

def ensure_initialized(self):
if not self.is_initialized:
self.api_versions = self.get_api_versions()
Expand Down
2 changes: 1 addition & 1 deletion azurelinuxagent/common/protocol/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def get_wireserver_endpoint(self):
logger.info("WireServer endpoint {0} read from file", self.endpoint)
return self.endpoint

logger.error("[GetWireserverEndpoint] Unexpected empty file {0}: {1}", file_path, str(e))
larohra marked this conversation as resolved.
Show resolved Hide resolved
logger.error("[GetWireserverEndpoint] Unexpected empty file {0}", file_path)
except (IOError, OSError) as e:
logger.error("[GetWireserverEndpoint] Error reading file {0}: {1}", file_path, str(e))
else:
Expand Down
317 changes: 141 additions & 176 deletions azurelinuxagent/common/protocol/wire.py

Large diffs are not rendered by default.

37 changes: 4 additions & 33 deletions azurelinuxagent/common/rdma.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,50 +27,21 @@
import azurelinuxagent.common.logger as logger
import azurelinuxagent.common.utils.fileutil as fileutil
import azurelinuxagent.common.utils.shellutil as shellutil
from azurelinuxagent.common.utils.textutil import parse_doc, find, getattrib


from azurelinuxagent.common.protocol.wire import SHARED_CONF_FILE_NAME

dapl_config_paths = [
'/etc/dat.conf',
'/etc/rdma/dat.conf',
'/usr/local/etc/dat.conf'
]

def setup_rdma_device(nd_version):
logger.verbose("Parsing SharedConfig XML contents for RDMA details")
xml_doc = parse_doc(
fileutil.read_file(os.path.join(conf.get_lib_dir(), SHARED_CONF_FILE_NAME)))
if xml_doc is None:
logger.error("Could not parse SharedConfig XML document")
return
instance_elem = find(xml_doc, "Instance")
if not instance_elem:
logger.error("Could not find <Instance> in SharedConfig document")
return

rdma_ipv4_addr = getattrib(instance_elem, "rdmaIPv4Address")
if not rdma_ipv4_addr:
logger.error(
"Could not find rdmaIPv4Address attribute on Instance element of SharedConfig.xml document")
def setup_rdma_device(nd_version, shared_conf):
logger.verbose("Fetching SharedConfig contents for RDMA details")
if shared_conf.rdma_ipv4_addr is None or shared_conf.rdma_mac_addr is None:
return

rdma_mac_addr = getattrib(instance_elem, "rdmaMacAddress")
if not rdma_mac_addr:
logger.error(
"Could not find rdmaMacAddress attribute on Instance element of SharedConfig.xml document")
return

# add colons to the MAC address (e.g. 00155D33FF1D ->
# 00:15:5D:33:FF:1D)
rdma_mac_addr = ':'.join([rdma_mac_addr[i:i+2]
for i in range(0, len(rdma_mac_addr), 2)])
logger.info("Found RDMA details. IPv4={0} MAC={1}".format(
rdma_ipv4_addr, rdma_mac_addr))

# Set up the RDMA device with collected informatino
RDMADeviceHandler(rdma_ipv4_addr, rdma_mac_addr, nd_version).start()
RDMADeviceHandler(shared_conf.rdma_ipv4_addr, shared_conf.rdma_mac_addr, nd_version).start()
logger.info("RDMA: device is set up")
return

Expand Down
2 changes: 1 addition & 1 deletion azurelinuxagent/daemon/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def daemon(self, child_args=None):
raise Exception("Attempt to setup RDMA without Wireserver")
protocol.client.update_goal_state(forced=True)

setup_rdma_device(nd_version)
setup_rdma_device(nd_version, protocol.client.get_shared_conf())
except Exception as e:
logger.error("Error setting up rdma device: %s" % e)
else:
Expand Down
2 changes: 2 additions & 0 deletions azurelinuxagent/ga/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ def stop(self):

def init_protocols(self):
self.protocol = self.protocol_util.get_protocol()
# Update the GoalState first time to instantiate all required objects for the monitor thread
self.protocol.update_goal_state()
larohra marked this conversation as resolved.
Show resolved Hide resolved
self.health_service = HealthService(self.protocol.get_endpoint())

def is_alive(self):
Expand Down
9 changes: 7 additions & 2 deletions azurelinuxagent/ga/remoteaccess.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from datetime import datetime, timedelta

from azurelinuxagent.common.event import add_event, WALAEventOperation
from azurelinuxagent.common.exception import RemoteAccessError
from azurelinuxagent.common.exception import RemoteAccessError, ProtocolError
from azurelinuxagent.common.future import ustr
from azurelinuxagent.common.utils.cryptutil import CryptUtil
from azurelinuxagent.common.version import AGENT_NAME, CURRENT_VERSION
Expand Down Expand Up @@ -62,7 +62,12 @@ def run(self):
if self.incarnation != current_incarnation:
# something changed. Handle remote access if any.
self.incarnation = current_incarnation
self.remote_access = self.protocol.client.get_remote_access()
try:
self.remote_access = self.protocol.client.get_remote_access()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what we discussed in the meeting - that this code would be reverted. Correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope not this code, that was the RDMA code. In this I added a log.warn incase there was a ProtocolError but reverted that change because this file in majorly empty

except ProtocolError as e:
logger.warn(
"Error when trying to initialize Remote Access, setting it to None. Error: {0}".format(e))
self.remote_access = None
self.handle_remote_access()
except Exception as e:
msg = u"Exception processing remote access handler: {0} {1}".format(ustr(e), traceback.format_exc())
Expand Down
45 changes: 25 additions & 20 deletions tests/ga/test_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ def test_collect_and_send_events_should_prepare_all_fields_for_all_event_files(s
# list.

# The container id value is obtained from the goal state and must be present in all telemetry events.
container_id_param = TelemetryEventParam("ContainerId", protocol.client.goal_state.container_id)
container_id_param = TelemetryEventParam("ContainerId", protocol.client.get_goal_state().container_id)
self.assertTrue(container_id_param in event.parameters)

# Same for GAVersion
Expand Down Expand Up @@ -850,18 +850,23 @@ def test_collect_and_send_with_call_wireserver_returns_http_error(self, mock_lib
@patch('azurelinuxagent.common.osutil.get_osutil')
@patch('azurelinuxagent.common.protocol.get_protocol_util')
@patch("azurelinuxagent.common.protocol.healthservice.HealthService._report")
@patch('azurelinuxagent.common.protocol.util.ProtocolUtil.get_protocol', return_value=WireProtocol('endpoint'))
@patch("azurelinuxagent.common.utils.restutil.http_get")
class TestExtensionMetricsDataTelemetry(AgentTestCase):

def setUp(self):
AgentTestCase.setUp(self)
event.init_event_logger(os.path.join(self.tmp_dir, "events"))
CGroupsTelemetry.reset()
clear_singleton_instances(ProtocolUtil)
protocol = WireProtocol('endpoint')
protocol.update_goal_state = MagicMock()
self.get_protocol = patch('azurelinuxagent.common.protocol.util.ProtocolUtil.get_protocol', return_value=protocol)
self.get_protocol.start()

def tearDown(self):
AgentTestCase.tearDown(self)
CGroupsTelemetry.reset()
self.get_protocol.stop()

@patch('azurelinuxagent.common.event.EventLogger.add_metric')
@patch('azurelinuxagent.common.event.EventLogger.add_event')
Expand Down Expand Up @@ -1238,32 +1243,32 @@ def test_generate_extension_metrics_telemetry_dictionary(self, *args):
self.assertEqual(message_json, None)


@patch('azurelinuxagent.common.event.EventLogger.add_event')
@patch("azurelinuxagent.common.utils.restutil.http_post")
@patch("azurelinuxagent.common.utils.restutil.http_get")
@patch('azurelinuxagent.common.protocol.wire.WireClient.get_goal_state')
@patch('azurelinuxagent.common.protocol.util.ProtocolUtil.get_protocol', return_value=WireProtocol('endpoint'))
@patch('azurelinuxagent.common.event.EventLogger.add_event')
@patch("azurelinuxagent.common.utils.restutil.http_get")
class TestMonitorFailure(AgentTestCase):

@patch("azurelinuxagent.common.protocol.healthservice.HealthService.report_host_plugin_heartbeat")
def test_error_heartbeat_creates_no_signal(self, patch_report_heartbeat, *args):
patch_http_get = args[2]
patch_add_event = args[4]
def test_error_heartbeat_creates_no_signal(self, patch_report_heartbeat, patch_http_get, patch_add_event, *args):

monitor_handler = get_monitor_handler()
monitor_handler.init_protocols()
monitor_handler.last_host_plugin_heartbeat = datetime.datetime.utcnow() - timedelta(hours=1)
protocol = WireProtocol('endpoint')
protocol.update_goal_state = MagicMock()
with patch('azurelinuxagent.common.protocol.util.ProtocolUtil.get_protocol', return_value=protocol):
monitor_handler.init_protocols()
monitor_handler.last_host_plugin_heartbeat = datetime.datetime.utcnow() - timedelta(hours=1)

patch_http_get.side_effect = IOError('client error')
monitor_handler.send_host_plugin_heartbeat()
patch_http_get.side_effect = IOError('client error')
monitor_handler.send_host_plugin_heartbeat()

# health report should not be made
self.assertEqual(0, patch_report_heartbeat.call_count)
# health report should not be made
self.assertEqual(0, patch_report_heartbeat.call_count)

# telemetry with failure details is sent
self.assertEqual(1, patch_add_event.call_count)
self.assertEqual('HostPluginHeartbeat', patch_add_event.call_args[1]['op'])
self.assertTrue('client error' in patch_add_event.call_args[1]['message'])
# telemetry with failure details is sent
self.assertEqual(1, patch_add_event.call_count)
self.assertEqual('HostPluginHeartbeat', patch_add_event.call_args[1]['op'])
self.assertTrue('client error' in patch_add_event.call_args[1]['message'])

self.assertEqual(False, patch_add_event.call_args[1]['is_success'])
monitor_handler.stop()
self.assertEqual(False, patch_add_event.call_args[1]['is_success'])
monitor_handler.stop()
8 changes: 4 additions & 4 deletions tests/ga/test_remoteaccess.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ def test_update_remote_access_conf_remote_access(self, _1, _2, _3):
protocol = WireProtocol('12.34.56.78')
goal_state = protocol.client.get_goal_state()
protocol.client.update_remote_access_conf(goal_state)
self.assertNotEquals(None, protocol.client.remote_access)
self.assertEquals(1, len(protocol.client.remote_access.user_list.users))
self.assertEquals('testAccount', protocol.client.remote_access.user_list.users[0].name)
self.assertEquals('encryptedPasswordString', protocol.client.remote_access.user_list.users[0].encrypted_password)
self.assertNotEquals(None, protocol.client.get_remote_access())
self.assertEquals(1, len(protocol.client.get_remote_access().user_list.users))
self.assertEquals('testAccount', protocol.client.get_remote_access().user_list.users[0].name)
self.assertEquals('encryptedPasswordString', protocol.client.get_remote_access().user_list.users[0].encrypted_password)

def test_parse_bad_remote_access_data(self):
data = "foobar"
Expand Down
58 changes: 0 additions & 58 deletions tests/ga/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -1426,64 +1426,6 @@ def test_write_pid_file_ignores_exceptions(self):
self.assertEqual(0, len(pid_files))
self.assertEqual(None, pid_file)

@patch('azurelinuxagent.common.protocol.wire.WireClient.get_goal_state',
return_value=GoalState(load_data('wire/goal_state.xml')))
def test_package_filter_for_agent_manifest(self, _):
larohra marked this conversation as resolved.
Show resolved Hide resolved

protocol = WireProtocol('12.34.56.78')
extension_config = ExtensionsConfig(load_data('wire/ext_conf.xml'))
agent_manifest = extension_config.vmagent_manifests.vmAgentManifests[0]

# has agent versions 13, 14
ga_manifest_1 = ExtensionManifest(load_data('wire/ga_manifest_1.xml'))

# has agent versions 13, 14, 15
ga_manifest_2 = ExtensionManifest(load_data('wire/ga_manifest_2.xml'))

goal_state = protocol.client.get_goal_state()
disk_cache = os.path.join(conf.get_lib_dir(),
AGENTS_MANIFEST_FILE_NAME.format(
agent_manifest.family,
goal_state.incarnation))

self.assertFalse(os.path.exists(disk_cache))
self.assertTrue(ga_manifest_1.allowed_versions is None)

with patch(
'azurelinuxagent.common.protocol.wire.WireClient'
'.get_gafamily_manifest',
return_value=ga_manifest_1):

pkg_list_1 = protocol.get_vmagent_pkgs(agent_manifest)
self.assertTrue(pkg_list_1 is not None)
self.assertTrue(len(pkg_list_1.versions) == 2)
self.assertTrue(pkg_list_1.versions[0].version == '2.2.13')
self.assertTrue(pkg_list_1.versions[0].uris[0].uri == 'url1_13')
self.assertTrue(pkg_list_1.versions[1].version == '2.2.14')
self.assertTrue(pkg_list_1.versions[1].uris[0].uri == 'url1_14')

self.assertTrue(os.path.exists(disk_cache))

with patch(
'azurelinuxagent.common.protocol.wire.WireClient'
'.get_gafamily_manifest',
return_value=ga_manifest_2):

pkg_list_2 = protocol.get_vmagent_pkgs(agent_manifest)
self.assertTrue(pkg_list_2 is not None)
self.assertTrue(len(pkg_list_2.versions) == 2)
self.assertTrue(pkg_list_2.versions[0].version == '2.2.13')
self.assertTrue(pkg_list_2.versions[0].uris[0].uri == 'url2_13')
self.assertTrue(pkg_list_2.versions[1].version == '2.2.14')
self.assertTrue(pkg_list_2.versions[1].uris[0].uri == 'url2_14')
# does not contain 2.2.15

self.assertTrue(os.path.exists(disk_cache))
self.assertTrue(ga_manifest_2.allowed_versions is not None)
self.assertTrue(len(ga_manifest_2.allowed_versions) == 2)
self.assertTrue(ga_manifest_2.allowed_versions[0] == '2.2.13')
self.assertTrue(ga_manifest_2.allowed_versions[1] == '2.2.14')

@patch('azurelinuxagent.common.conf.get_extensions_enabled', return_value=False)
def test_update_happens_when_extensions_disabled(self, _):
"""
Expand Down
Loading