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

Onboarding MDE for Linux to LISA #3113

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Using Azure SAS Uri for getting onboarding script
  • Loading branch information
Zeeshan Akhter committed Dec 22, 2023
commit a7d6c14321bd824004b6c8207cdbdc02672dd416
19 changes: 9 additions & 10 deletions lisa/tools/mde.py
Original file line number Diff line number Diff line change
@@ -2,17 +2,14 @@
# Licensed under the MIT license.

import os
import sys
import json
import requests
from pathlib import Path, PurePath
from pathlib import Path
from typing import Any

from lisa.executable import Tool
from lisa.executable import CustomScriptBuilder, CustomScript
#from . import RemoteCopy, Whoami, Curl
from .remote_copy import RemoteCopy
from .whoami import Whoami
from lisa.base_tools import Wget

class MDE(Tool):
Copy link
Member

Choose a reason for hiding this comment

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

It's used by MDE test suite only, so it can be in the same file with the test suite.

@property
@@ -50,23 +47,25 @@ def _install(self) -> bool:
return self._check_exists()


def onboard(self, onboarding_script: PurePath) -> bool:
def onboard(self, onboarding_script_sas_uri: str) -> bool:
if not self._check_exists():
self._log.error("MDE is not installed, onboarding not possible")
return False

username = self.node.tools[Whoami].get_username()
wget = self.node.tools[Wget]

remote_copy = self.node.tools[RemoteCopy]
remote_copy.copy_to_remote(onboarding_script, PurePath(f"/home/{username}/MicrosoftDefenderATPOnboardingLinuxServer.py"))
download_path = wget.get(
url=onboarding_script_sas_uri,
filename="MicrosoftDefenderATPOnboardingLinuxServer.py",
)

if not self.get_mde_installer():
self._log.error("Unable to download mde_installer.sh script. MDE can't be onboarded")

script: CustomScript = self.node.tools[self._mde_installer]

self._log.info('Onboarding MDE')
result1 = script.run(parameters=f"--onboard /home/{username}/MicrosoftDefenderATPOnboardingLinuxServer.py/MicrosoftDefenderATPOnboardingLinuxServer.py", sudo=True)
result1 = script.run(parameters=f"--onboard {download_path}", sudo=True)
self._log.info(result1)

output = self.get_result('health --field licensed')
4 changes: 4 additions & 0 deletions microsoft/runbook/my.yml
Original file line number Diff line number Diff line change
@@ -10,6 +10,10 @@ variable:
is_secret: true
is_case_visible: True
value: ""
- name: onboarding_script_sas_uri
is_secret: true
is_case_visible: True
value: ""
- name: location
value: "westus3"
- name: keep_environment
8 changes: 4 additions & 4 deletions microsoft/testsuites/vm_extensions/mde.py
Original file line number Diff line number Diff line change
@@ -29,9 +29,9 @@ class MDE(TestSuite):

def before_case(self, log: Logger, **kwargs: Any) -> None:
variables = kwargs["variables"]
self.onboarding_script = variables.get("onboarding_script", "")
if not self.onboarding_script:
raise SkippedException("Onboarding script is not provided.")
self.onboarding_script_sas_uri = variables.get("onboarding_script_sas_uri", "")
if not self.onboarding_script_sas_uri:
raise SkippedException("Onboarding script SAS URI is not provided.")

@TestCaseMetadata(
description="""
@@ -61,7 +61,7 @@ def verify_mde(self, node: Node, log: Logger, result: TestResult) -> None:

def verify_onboard(self, node: Node, log: Logger, result: TestResult) -> None:

onboarding_result = node.tools[mdatp].onboard(PurePath(self.onboarding_script))
onboarding_result = node.tools[mdatp].onboard(self.onboarding_script_sas_uri)

assert_that(onboarding_result).is_equal_to(True)