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: 7 additions & 1 deletion msa_sdk/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __init__(self, customer_id=None, name=None, manufacturer_id=None,
device_external=None, log_enabled=True,
log_more_enabled=True, mail_alerting=True,
reporting=False, snmp_community="ubiqube",
device_id=None, management_port=None):
device_id=None, management_port=None, hostname=None):
"""
Initialize.

Expand Down Expand Up @@ -48,6 +48,8 @@ def __init__(self, customer_id=None, name=None, manufacturer_id=None,
Device ID
management_port: Integer
Management Port
hostname: String
Hostname
fail: Bool
Fail creating the device

Expand Down Expand Up @@ -79,6 +81,7 @@ def __init__(self, customer_id=None, name=None, manufacturer_id=None,
self.configuration = {}
self.device_id = device_id
self.management_port = management_port
self.hostname=hostname
self.fail = None

if device_id:
Expand Down Expand Up @@ -112,6 +115,7 @@ def create(self):
"mailAlerting": self.mail_alerting,
"passwordAdmin": self.password_admin,
"externalReference": self.device_external,
"hostname": self.hostname,
"login": self.login,
"name": self.name,
"password": self.password,
Expand Down Expand Up @@ -282,6 +286,8 @@ def read(self, by_ref=False):
self.mail_alerting = device_info["mailAlerting"]
self.use_nat = device_info["useNat"]
self.snmp_community = device_info["snmpCommunity"]
self.device_external = device_info["externalReference"]
self.hostname = device_info["hostname"]

return self.content

Expand Down
47 changes: 47 additions & 0 deletions msa_sdk/profile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""
This module provides the Profile class for interacting with profiles in the MSA SDK.

The Profile class inherits from MSA_API and provides methods to check the existence
of profiles and perform other profile-related operations.
"""

import json

from msa_sdk.msa_api import MSA_API


class Profile(MSA_API):
"""
A class to represent a profile in the MSA SDK.

This class provides methods to interact with profiles.
"""

def __init__(self):
"""
Initialize a Profile instance.

Sets up the API path for profile operations.
"""
MSA_API.__init__(self)
self.api_path = "/profile"

def exist(self, reference) -> bool:
"""
Check if a profile exists by reference.

Parameters
----------
reference : str
The reference identifier for the profile.

Returns
-------
bool
True if the profile exists, False otherwise.
"""
self.action = 'Check Profile exist by reference'
self.path = '{}/v1/exist/{}'.format(self.api_path, reference)
self._call_post()
result = json.loads(self.content)
return result.get('exist', False)
20 changes: 20 additions & 0 deletions tests/test_profie.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
Test Profile
"""

from unittest.mock import patch

from util import profile_fixture


def test_exist(profile_fixture):
"""
Test exist profile by reference
"""
with patch('msa_sdk.msa_api.MSA_API._call_post') as mock_call_post:
profile = profile_fixture
reference = "test1"
profile.exist(reference)

assert profile.path == "/profile/v1/exist/test1"
mock_call_post.assert_called_once()
14 changes: 13 additions & 1 deletion tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from msa_sdk.device import Device
from msa_sdk.orchestration import Orchestration
from msa_sdk.order import Order
from msa_sdk.profile import Profile
from msa_sdk.repository import Repository


Expand Down Expand Up @@ -39,7 +40,7 @@ def device_info():
'"managementInterface":"","login":"root",'
'"password":"$ubiqube","passwordAdmin":"","logEnabled":false,'
'"logMoreEnabled":false,"mailAlerting":false,"reporting":false,'
'"useNat":true,"snmpCommunity":""}')
'"useNat":true,"snmpCommunity":"","hostname":"test"}')


def device_list():
Expand Down Expand Up @@ -248,6 +249,17 @@ def conf_profile_fixture():
conf_profile = ConfProfile(100)
return conf_profile

@pytest.fixture
def profile_fixture():
"""Profile fixture."""
with patch('requests.post') as mock_post:
mock_post.return_value.json.return_value = {'token': '12345qwert'}

with patch('msa_sdk.msa_api.host_port') as mock_host_port:
mock_host_port.return_value = ('api_hostname', '8080')
profile = Profile()
return profile


@pytest.fixture
def conf_backup_fixture():
Expand Down