From 291230c78de90935f381b7e0bf0a3a16a628b152 Mon Sep 17 00:00:00 2001 From: Saimon Michelson Date: Tue, 19 May 2026 19:10:47 -0400 Subject: [PATCH 1/9] support edge filer stats module --- cterasdk/edge/__init__.py | 1 + cterasdk/edge/enum.py | 40 +++++++++++++ cterasdk/edge/remote.py | 2 +- cterasdk/objects/services.py | 4 +- cterasdk/objects/synchronous/core.py | 3 + cterasdk/objects/synchronous/edge.py | 18 ++++-- docs/source/UserGuides/Edge/Configuration.rst | 59 +++++++++++++++++++ 7 files changed, 119 insertions(+), 8 deletions(-) diff --git a/cterasdk/edge/__init__.py b/cterasdk/edge/__init__.py index be39ec2b..fb1bf0b1 100644 --- a/cterasdk/edge/__init__.py +++ b/cterasdk/edge/__init__.py @@ -30,6 +30,7 @@ 'shares', 'shell', 'smb', + 'statistics' 'support', 'sync', 'syslog', diff --git a/cterasdk/edge/enum.py b/cterasdk/edge/enum.py index 611f652a..7e2b66db 100644 --- a/cterasdk/edge/enum.py +++ b/cterasdk/edge/enum.py @@ -437,3 +437,43 @@ class ResourceError: """ FileExists = 'File exists' Forbidden = 'Creating a folder in this location is forbidden' + + +class Metric: + """ + Metric + + :ivar str CPU: CPU + :ivar str Memory: Memory + :ivar str Volume: Volume + :ivar str Cache: Cache Stats + :ivar str Connections: Connections + :ivar str Disk: Disk I/O + :ivar str Local: Local I/O + :ivar str CloudSync: Cloud Sync + """ + CPU = 'cpu' + Memory = 'memory' + Volume = 'volume' + Cache = 'cache' + Connections = 'connections' + Disk = 'disk_io' + Local = 'local_io' + CloudSync = 'cloud_io' + + +class Interval: + """ + Interval + + :ivar str Hour: Hour (Real-time) + :ivar str Day: Day + :ivar str Week: Week + :ivar str Month: Month + :ivar str Year: Year + """ + Hour = 'hour' + Day = 'day' + Week = 'week' + Month = 'month' + Year = 'year' diff --git a/cterasdk/edge/remote.py b/cterasdk/edge/remote.py index 67b4645f..ebb05850 100644 --- a/cterasdk/edge/remote.py +++ b/cterasdk/edge/remote.py @@ -14,7 +14,7 @@ def remote_access(device, Portal): logger.info("Enabling remote access. %s", {'tenant': device_tenant, 'device': device_name}) token = authn_token(Portal, device_tenant, device_name) device_object = create_device_object(device) - device_object.sso(token) + device_object.sso(token, {Portal._session_id_key: Portal.get_session_id()}) logger.info("Enabled remote access. %s", {'tenant': device_tenant, 'device': device_name}) return device_object diff --git a/cterasdk/objects/services.py b/cterasdk/objects/services.py index fe5e1571..75c5a700 100644 --- a/cterasdk/objects/services.py +++ b/cterasdk/objects/services.py @@ -143,13 +143,13 @@ def test(self): def _session_id_key(self): return NotImplementedError("Subclass must implement the '_session_id_key' property") - def get_session_id(self): + def get_session_id(self, response_url=None): """ Get Session Identifier :return str: Session ID """ - return self._default.cookie_jar.get(self._default.baseurl, self._session_id_key) + return self._default.cookie_jar.get(response_url if response_url else self._default.baseurl, self._session_id_key) def set_session_id(self, session_id): self._default.cookie_jar.update_cookies({self._session_id_key: session_id}, self._default.baseurl) diff --git a/cterasdk/objects/synchronous/core.py b/cterasdk/objects/synchronous/core.py index 0b1769de..4e17d342 100644 --- a/cterasdk/objects/synchronous/core.py +++ b/cterasdk/objects/synchronous/core.py @@ -93,6 +93,9 @@ def context(self): def _session_id_key(self): return 'JSESSIONID' + def get_session_id(self): + return super().get_session_id(self.ctera.baseurl) + def _authenticator(self, url): return authenticators.core(self.session(), url, self.context) diff --git a/cterasdk/objects/synchronous/edge.py b/cterasdk/objects/synchronous/edge.py index dbe2c9ba..e5783c82 100644 --- a/cterasdk/objects/synchronous/edge.py +++ b/cterasdk/objects/synchronous/edge.py @@ -11,7 +11,7 @@ afp, aio, antivirus, array, audit, backup, cache, cli, config, connection, ctera_migrate, dedup, directoryservice, drive, files, firmware, ftp, groups, licenses, login, logs, mail, network, nfs, ntp, power, remote, rsync, ransom_protect, services, - shares, shell, smb, snmp, ssh, ssl, support, sync, syslog, tasks, telnet, + shares, shell, smb, snmp, ssh, ssl, statistics, support, sync, syslog, tasks, telnet, timezone, users, volumes, ) @@ -27,6 +27,7 @@ def __init__(self, edge, Portal): else: self.migrate = edge.default.clone(clients.Migrate, EndpointBuilder.new(edge.base, '/migration/rest/v1')) self.api = edge.default.clone(clients.API, EndpointBuilder.new(edge.base, '/admingui/api')) + self.stats = edge.default.clone(clients.JSON, EndpointBuilder.new(edge.base, '/stats')) self.io = IO(edge) @@ -108,6 +109,7 @@ def __init__(self, host=None, port=None, https=True, Portal=None, *, base=None): self.snmp = snmp.SNMP(self) self.ssh = ssh.SSH(self) self.ssl = modules.initialize(ssl.SSLModule, self) + self.statistics = statistics.Statistics(self) self.support = support.Support(self) self.sync = sync.Sync(self) self.syslog = syslog.Syslog(self) @@ -151,8 +153,14 @@ def initialized(self): def test(self): return connection.test(self) - def sso(self, ticket): - """ Login using Single Sign On""" + def sso(self, ticket, remote): + """ + Single Sign on from CTERA Portal to CTERA Edge Filer. + + :param str ticket: SSO Ticket + :param dict remote: CTERA Portal Session Cookie + """ + self.default.cookie_jar.update_cookies(remote, self.default.baseurl) self._login_object.sso(ticket) self.session().start_session(self) @@ -164,5 +172,5 @@ def _omit_fields(self): return super()._omit_fields + ['afp', 'aio', 'array', 'audit', 'antivirus', 'backup', 'cache', 'cli', 'config', 'ctera_migrate', 'dedup', 'directoryservice', 'drive', 'files', 'firmware', 'ftp', 'groups', 'licenses', 'logs', 'mail', 'network', 'nfs', 'ntp', 'power', 'ransom_protect', 'rsync', 'services', 'shares', 'shell', - 'smb', 'snmp', 'ssh', 'ssl', 'support', 'sync', 'syslog', 'tasks', 'telnet', 'timezone', - 'users', 'volumes'] + 'smb', 'snmp', 'ssh', 'ssl', 'statistics', 'support', 'sync', 'syslog', 'tasks', 'telnet', + 'timezone', 'users', 'volumes'] diff --git a/docs/source/UserGuides/Edge/Configuration.rst b/docs/source/UserGuides/Edge/Configuration.rst index 95ef3092..96eb5333 100644 --- a/docs/source/UserGuides/Edge/Configuration.rst +++ b/docs/source/UserGuides/Edge/Configuration.rst @@ -1505,6 +1505,65 @@ SSH edge.ssh.disable() +Statistics +========== + +.. automethod:: cterasdk.edge.statistics.Statistics.cpu + :noindex: + +.. code-block:: python + + edge.statistics.cpu(edge_enum.Interval.Day) + +.. automethod:: cterasdk.edge.statistics.Statistics.memory + :noindex: + +.. code-block:: python + + edge.statistics.memory(edge_enum.Interval.Day) + +.. automethod:: cterasdk.edge.statistics.Statistics.volume + :noindex: + +.. code-block:: python + + edge.statistics.volume(edge_enum.Interval.Day) + +.. automethod:: cterasdk.edge.statistics.Statistics.cache + :noindex: + +.. code-block:: python + + edge.statistics.cache(edge_enum.Interval.Day) + +.. automethod:: cterasdk.edge.statistics.Statistics.connections + :noindex: + +.. code-block:: python + + edge.statistics.connections(edge_enum.Interval.Day) + +.. automethod:: cterasdk.edge.statistics.Statistics.disk + :noindex: + +.. code-block:: python + + edge.statistics.disk(edge_enum.Interval.Day) + +.. automethod:: cterasdk.edge.statistics.Statistics.local_io + :noindex: + +.. code-block:: python + + edge.statistics.local_io(edge_enum.Interval.Day) + +.. automethod:: cterasdk.edge.statistics.Statistics.cloudsync + :noindex: + +.. code-block:: python + + edge.statistics.cloudsync(edge_enum.Interval.Day) + Miscellaneous ------------- From 99173f57176ca47dbf9e5c2a926c8a8c69e999e2 Mon Sep 17 00:00:00 2001 From: Saimon Michelson Date: Tue, 19 May 2026 19:12:05 -0400 Subject: [PATCH 2/9] add missing modules --- cterasdk/edge/statistics.py | 91 ++++++++++++++++++++++++++++++++ tests/ut/edge/test_statistics.py | 40 ++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 cterasdk/edge/statistics.py create mode 100644 tests/ut/edge/test_statistics.py diff --git a/cterasdk/edge/statistics.py b/cterasdk/edge/statistics.py new file mode 100644 index 00000000..b1625716 --- /dev/null +++ b/cterasdk/edge/statistics.py @@ -0,0 +1,91 @@ +from .enum import Metric +from .base_command import BaseCommand + + +class Statistics(BaseCommand): + """ Edge Filer Statistics API """ + + def cpu(self, interval): + """ + CPU Statistics + + :param cterasdk.edge.enum.Interval interval: Interval + :return: Statistics Object + :rtype: cterasdk.common.object.Object + """ + return self._statistics(Metric.CPU, interval) + + def memory(self, interval): + """ + Memory Statistics + + :param cterasdk.edge.enum.Interval interval: Interval + :return: Statistics Object + :rtype: cterasdk.common.object.Object + """ + return self._statistics(Metric.Memory, interval) + + def volume(self, interval): + """ + Volume Statistics + + :param cterasdk.edge.enum.Interval interval: Interval + :return: Statistics Object + :rtype: cterasdk.common.object.Object + """ + return self._statistics(Metric.Volume, interval) + + def cache(self, interval): + """ + Cache Statistics + + :param cterasdk.edge.enum.Interval interval: Interval + :return: Statistics Object + :rtype: cterasdk.common.object.Object + """ + return self._statistics(Metric.Cache, interval) + + def connections(self, interval): + """ + Connections Statistics + + :param cterasdk.edge.enum.Interval interval: Interval + :return: Statistics Object + :rtype: cterasdk.common.object.Object + """ + return self._statistics(Metric.Connections, interval) + + def disk(self, interval): + """ + Disk I/O Statistics + + :param cterasdk.edge.enum.Interval interval: Interval + :return: Statistics Object + :rtype: cterasdk.common.object.Object + """ + return self._statistics(Metric.Disk, interval) + + def local_io(self, interval): + """ + Local I/O Statistics + + :param cterasdk.edge.enum.Interval interval: Interval + :return: Statistics Object + :rtype: cterasdk.common.object.Object + """ + return self._statistics(Metric.Local, interval) + + def cloudsync(self, interval): + """ + Cloud Synchronization Statistics + + :param cterasdk.edge.enum.Interval interval: Interval + :return: Statistics Object + :rtype: cterasdk.common.object.Object + """ + return self._statistics(Metric.CloudSync, interval) + + def _statistics(self, metric, interval): + return self._edge.clients.stats.get(metric, params={ + 'interval': interval + }) \ No newline at end of file diff --git a/tests/ut/edge/test_statistics.py b/tests/ut/edge/test_statistics.py new file mode 100644 index 00000000..e8a103f1 --- /dev/null +++ b/tests/ut/edge/test_statistics.py @@ -0,0 +1,40 @@ +from cterasdk.edge import statistics +from cterasdk.edge.enum import Interval, Metric +from tests.ut.edge import base_edge + + +class TestEdgeStatistics(base_edge.BaseEdgeTest): + + def setUp(self): + super().setUp() + + self.metrics = ( + Metric.CPU, + Metric.Memory, + Metric.Volume, + Metric.Cache, + Metric.Connections, + Metric.Disk, + Metric.Local, + Metric.CloudSync, + ) + + self.intervals = ( + Interval.Hour, + Interval.Day, + Interval.Week, + Interval.Month, + Interval.Year, + ) + + def test_statistics(self): + for metric in self.metrics: + for interval in self.intervals: + self._init_filer() + + statistics.Statistics(self._filer)._statistics(metric, interval) + + self._filer.api.get.assert_called_once_with( + metric, + params={'interval': interval} + ) From c977f8054d9e54e06ce3d055866b4e802002bdef Mon Sep 17 00:00:00 2001 From: Saimon Michelson Date: Tue, 19 May 2026 19:18:12 -0400 Subject: [PATCH 3/9] update the tests --- tests/ut/edge/test_statistics.py | 86 +++++++++++++++++++++----------- 1 file changed, 56 insertions(+), 30 deletions(-) diff --git a/tests/ut/edge/test_statistics.py b/tests/ut/edge/test_statistics.py index e8a103f1..b02351d1 100644 --- a/tests/ut/edge/test_statistics.py +++ b/tests/ut/edge/test_statistics.py @@ -7,34 +7,60 @@ class TestEdgeStatistics(base_edge.BaseEdgeTest): def setUp(self): super().setUp() + self.intervals = (Interval.Hour, Interval.Day, Interval.Week, Interval.Month, Interval.Year) - self.metrics = ( - Metric.CPU, - Metric.Memory, - Metric.Volume, - Metric.Cache, - Metric.Connections, - Metric.Disk, - Metric.Local, - Metric.CloudSync, - ) - - self.intervals = ( - Interval.Hour, - Interval.Day, - Interval.Week, - Interval.Month, - Interval.Year, - ) - - def test_statistics(self): - for metric in self.metrics: - for interval in self.intervals: - self._init_filer() - - statistics.Statistics(self._filer)._statistics(metric, interval) - - self._filer.api.get.assert_called_once_with( - metric, - params={'interval': interval} - ) + def test_cpu(self): + self._init_filer() + for interval in self.intervals: + statistics.Statistics(self._filer).cpu(interval) + self._filer.api.get.assert_called_with(Metric.CPU, params={'interval': interval}) + self._filer.api.get.reset_mock() + + def test_memory(self): + self._init_filer() + for interval in self.intervals: + statistics.Statistics(self._filer).memory(interval) + self._filer.api.get.assert_called_with(Metric.Memory, params={'interval': interval}) + self._filer.api.get.reset_mock() + + def test_volume(self): + self._init_filer() + for interval in self.intervals: + statistics.Statistics(self._filer).volume(interval) + self._filer.api.get.assert_called_with(Metric.Volume, params={'interval': interval}) + self._filer.api.get.reset_mock() + + def test_cache(self): + self._init_filer() + for interval in self.intervals: + statistics.Statistics(self._filer).cache(interval) + self._filer.api.get.assert_called_with(Metric.Cache, params={'interval': interval}) + self._filer.api.get.reset_mock() + + def test_connections(self): + self._init_filer() + for interval in self.intervals: + statistics.Statistics(self._filer).connections(interval) + self._filer.api.get.assert_called_with(Metric.Connections, params={'interval': interval}) + self._filer.api.get.reset_mock() + + def test_disk(self): + self._init_filer() + for interval in self.intervals: + statistics.Statistics(self._filer).disk(interval) + self._filer.api.get.assert_called_with(Metric.Disk, params={'interval': interval}) + self._filer.api.get.reset_mock() + + def test_local_io(self): + self._init_filer() + for interval in self.intervals: + statistics.Statistics(self._filer).local_io(interval) + self._filer.api.get.assert_called_with(Metric.Local, params={'interval': interval}) + self._filer.api.get.reset_mock() + + def test_cloudsync(self): + self._init_filer() + for interval in self.intervals: + statistics.Statistics(self._filer).cloudsync(interval) + self._filer.api.get.assert_called_with(Metric.CloudSync, params={'interval': interval}) + self._filer.api.get.reset_mock() From 72ddb7e3ba56e6774a2e7a50c5e2c8717dec297c Mon Sep 17 00:00:00 2001 From: Saimon Michelson Date: Tue, 19 May 2026 19:22:30 -0400 Subject: [PATCH 4/9] update statistics --- tests/ut/edge/test_statistics.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tests/ut/edge/test_statistics.py b/tests/ut/edge/test_statistics.py index b02351d1..b5826c5f 100644 --- a/tests/ut/edge/test_statistics.py +++ b/tests/ut/edge/test_statistics.py @@ -14,53 +14,45 @@ def test_cpu(self): for interval in self.intervals: statistics.Statistics(self._filer).cpu(interval) self._filer.api.get.assert_called_with(Metric.CPU, params={'interval': interval}) - self._filer.api.get.reset_mock() def test_memory(self): self._init_filer() for interval in self.intervals: statistics.Statistics(self._filer).memory(interval) self._filer.api.get.assert_called_with(Metric.Memory, params={'interval': interval}) - self._filer.api.get.reset_mock() def test_volume(self): self._init_filer() for interval in self.intervals: statistics.Statistics(self._filer).volume(interval) self._filer.api.get.assert_called_with(Metric.Volume, params={'interval': interval}) - self._filer.api.get.reset_mock() def test_cache(self): self._init_filer() for interval in self.intervals: statistics.Statistics(self._filer).cache(interval) self._filer.api.get.assert_called_with(Metric.Cache, params={'interval': interval}) - self._filer.api.get.reset_mock() def test_connections(self): self._init_filer() for interval in self.intervals: statistics.Statistics(self._filer).connections(interval) self._filer.api.get.assert_called_with(Metric.Connections, params={'interval': interval}) - self._filer.api.get.reset_mock() def test_disk(self): self._init_filer() for interval in self.intervals: statistics.Statistics(self._filer).disk(interval) self._filer.api.get.assert_called_with(Metric.Disk, params={'interval': interval}) - self._filer.api.get.reset_mock() def test_local_io(self): self._init_filer() for interval in self.intervals: statistics.Statistics(self._filer).local_io(interval) self._filer.api.get.assert_called_with(Metric.Local, params={'interval': interval}) - self._filer.api.get.reset_mock() def test_cloudsync(self): self._init_filer() for interval in self.intervals: statistics.Statistics(self._filer).cloudsync(interval) self._filer.api.get.assert_called_with(Metric.CloudSync, params={'interval': interval}) - self._filer.api.get.reset_mock() From 2503df1c81fab0b9274a4142d6f04faa34bb9420 Mon Sep 17 00:00:00 2001 From: Saimon Michelson Date: Tue, 19 May 2026 19:23:31 -0400 Subject: [PATCH 5/9] update test statistics --- tests/ut/edge/test_statistics.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/ut/edge/test_statistics.py b/tests/ut/edge/test_statistics.py index b5826c5f..5d9cf8e4 100644 --- a/tests/ut/edge/test_statistics.py +++ b/tests/ut/edge/test_statistics.py @@ -12,47 +12,47 @@ def setUp(self): def test_cpu(self): self._init_filer() for interval in self.intervals: - statistics.Statistics(self._filer).cpu(interval) + statistics.Statistics(self._filer).statistics.cpu(interval) self._filer.api.get.assert_called_with(Metric.CPU, params={'interval': interval}) def test_memory(self): self._init_filer() for interval in self.intervals: - statistics.Statistics(self._filer).memory(interval) + statistics.Statistics(self._filer).statistics.memory(interval) self._filer.api.get.assert_called_with(Metric.Memory, params={'interval': interval}) def test_volume(self): self._init_filer() for interval in self.intervals: - statistics.Statistics(self._filer).volume(interval) + statistics.Statistics(self._filer).statistics.volume(interval) self._filer.api.get.assert_called_with(Metric.Volume, params={'interval': interval}) def test_cache(self): self._init_filer() for interval in self.intervals: - statistics.Statistics(self._filer).cache(interval) + statistics.Statistics(self._filer).statistics.cache(interval) self._filer.api.get.assert_called_with(Metric.Cache, params={'interval': interval}) def test_connections(self): self._init_filer() for interval in self.intervals: - statistics.Statistics(self._filer).connections(interval) + statistics.Statistics(self._filer).statistics.connections(interval) self._filer.api.get.assert_called_with(Metric.Connections, params={'interval': interval}) def test_disk(self): self._init_filer() for interval in self.intervals: - statistics.Statistics(self._filer).disk(interval) + statistics.Statistics(self._filer).statistics.disk(interval) self._filer.api.get.assert_called_with(Metric.Disk, params={'interval': interval}) def test_local_io(self): self._init_filer() for interval in self.intervals: - statistics.Statistics(self._filer).local_io(interval) + statistics.Statistics(self._filer).statistics.local_io(interval) self._filer.api.get.assert_called_with(Metric.Local, params={'interval': interval}) def test_cloudsync(self): self._init_filer() for interval in self.intervals: - statistics.Statistics(self._filer).cloudsync(interval) + statistics.Statistics(self._filer).statistics.cloudsync(interval) self._filer.api.get.assert_called_with(Metric.CloudSync, params={'interval': interval}) From 69d2616789ff14e6e4f2c82515ee85fa00b5c065 Mon Sep 17 00:00:00 2001 From: Saimon Michelson Date: Tue, 19 May 2026 19:25:48 -0400 Subject: [PATCH 6/9] update tests --- tests/ut/edge/test_statistics.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/tests/ut/edge/test_statistics.py b/tests/ut/edge/test_statistics.py index 5d9cf8e4..0ece0312 100644 --- a/tests/ut/edge/test_statistics.py +++ b/tests/ut/edge/test_statistics.py @@ -10,49 +10,50 @@ def setUp(self): self.intervals = (Interval.Hour, Interval.Day, Interval.Week, Interval.Month, Interval.Year) def test_cpu(self): - self._init_filer() for interval in self.intervals: - statistics.Statistics(self._filer).statistics.cpu(interval) + self._init_filer() + statistics.Statistics(self._filer).cpu(interval) self._filer.api.get.assert_called_with(Metric.CPU, params={'interval': interval}) def test_memory(self): self._init_filer() for interval in self.intervals: - statistics.Statistics(self._filer).statistics.memory(interval) + self._init_filer() + statistics.Statistics(self._filer).memory(interval) self._filer.api.get.assert_called_with(Metric.Memory, params={'interval': interval}) def test_volume(self): - self._init_filer() for interval in self.intervals: - statistics.Statistics(self._filer).statistics.volume(interval) + self._init_filer() + statistics.Statistics(self._filer).volume(interval) self._filer.api.get.assert_called_with(Metric.Volume, params={'interval': interval}) def test_cache(self): - self._init_filer() for interval in self.intervals: - statistics.Statistics(self._filer).statistics.cache(interval) + self._init_filer() + statistics.Statistics(self._filer).cache(interval) self._filer.api.get.assert_called_with(Metric.Cache, params={'interval': interval}) def test_connections(self): - self._init_filer() for interval in self.intervals: - statistics.Statistics(self._filer).statistics.connections(interval) + self._init_filer() + statistics.Statistics(self._filer).connections(interval) self._filer.api.get.assert_called_with(Metric.Connections, params={'interval': interval}) def test_disk(self): - self._init_filer() for interval in self.intervals: - statistics.Statistics(self._filer).statistics.disk(interval) + self._init_filer() + statistics.Statistics(self._filer).disk(interval) self._filer.api.get.assert_called_with(Metric.Disk, params={'interval': interval}) def test_local_io(self): - self._init_filer() for interval in self.intervals: - statistics.Statistics(self._filer).statistics.local_io(interval) + self._init_filer() + statistics.Statistics(self._filer).local_io(interval) self._filer.api.get.assert_called_with(Metric.Local, params={'interval': interval}) def test_cloudsync(self): - self._init_filer() for interval in self.intervals: - statistics.Statistics(self._filer).statistics.cloudsync(interval) + self._init_filer() + statistics.Statistics(self._filer).cloudsync(interval) self._filer.api.get.assert_called_with(Metric.CloudSync, params={'interval': interval}) From f166ee0bf2c7660190031313baafa2aacc8a31ad Mon Sep 17 00:00:00 2001 From: Saimon Michelson Date: Tue, 19 May 2026 19:41:28 -0400 Subject: [PATCH 7/9] update tests to mock client --- tests/ut/edge/test_statistics.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tests/ut/edge/test_statistics.py b/tests/ut/edge/test_statistics.py index 0ece0312..127e172a 100644 --- a/tests/ut/edge/test_statistics.py +++ b/tests/ut/edge/test_statistics.py @@ -1,3 +1,5 @@ +from unittest import mock + from cterasdk.edge import statistics from cterasdk.edge.enum import Interval, Metric from tests.ut.edge import base_edge @@ -7,53 +9,54 @@ class TestEdgeStatistics(base_edge.BaseEdgeTest): def setUp(self): super().setUp() + self._filer.stats.get = mock.MagicMock() self.intervals = (Interval.Hour, Interval.Day, Interval.Week, Interval.Month, Interval.Year) def test_cpu(self): for interval in self.intervals: self._init_filer() statistics.Statistics(self._filer).cpu(interval) - self._filer.api.get.assert_called_with(Metric.CPU, params={'interval': interval}) + self._filer.stats.get.assert_called_with(Metric.CPU, params={'interval': interval}) def test_memory(self): self._init_filer() for interval in self.intervals: self._init_filer() statistics.Statistics(self._filer).memory(interval) - self._filer.api.get.assert_called_with(Metric.Memory, params={'interval': interval}) + self._filer.stats.get.assert_called_with(Metric.Memory, params={'interval': interval}) def test_volume(self): for interval in self.intervals: self._init_filer() statistics.Statistics(self._filer).volume(interval) - self._filer.api.get.assert_called_with(Metric.Volume, params={'interval': interval}) + self._filer.stats.get.assert_called_with(Metric.Volume, params={'interval': interval}) def test_cache(self): for interval in self.intervals: self._init_filer() statistics.Statistics(self._filer).cache(interval) - self._filer.api.get.assert_called_with(Metric.Cache, params={'interval': interval}) + self._filer.stats.get.assert_called_with(Metric.Cache, params={'interval': interval}) def test_connections(self): for interval in self.intervals: self._init_filer() statistics.Statistics(self._filer).connections(interval) - self._filer.api.get.assert_called_with(Metric.Connections, params={'interval': interval}) + self._filer.stats.get.assert_called_with(Metric.Connections, params={'interval': interval}) def test_disk(self): for interval in self.intervals: self._init_filer() statistics.Statistics(self._filer).disk(interval) - self._filer.api.get.assert_called_with(Metric.Disk, params={'interval': interval}) + self._filer.stats.get.assert_called_with(Metric.Disk, params={'interval': interval}) def test_local_io(self): for interval in self.intervals: self._init_filer() statistics.Statistics(self._filer).local_io(interval) - self._filer.api.get.assert_called_with(Metric.Local, params={'interval': interval}) + self._filer.stats.get.assert_called_with(Metric.Local, params={'interval': interval}) def test_cloudsync(self): for interval in self.intervals: self._init_filer() statistics.Statistics(self._filer).cloudsync(interval) - self._filer.api.get.assert_called_with(Metric.CloudSync, params={'interval': interval}) + self._filer.stats.get.assert_called_with(Metric.CloudSync, params={'interval': interval}) From ffc4d108249d46be081d2f63b84f13c09d592d71 Mon Sep 17 00:00:00 2001 From: Saimon Michelson Date: Tue, 19 May 2026 19:42:49 -0400 Subject: [PATCH 8/9] update mock --- tests/ut/edge/test_statistics.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/ut/edge/test_statistics.py b/tests/ut/edge/test_statistics.py index 127e172a..c1988972 100644 --- a/tests/ut/edge/test_statistics.py +++ b/tests/ut/edge/test_statistics.py @@ -9,54 +9,54 @@ class TestEdgeStatistics(base_edge.BaseEdgeTest): def setUp(self): super().setUp() - self._filer.stats.get = mock.MagicMock() + self._filer.clients.clients.stats.get = mock.MagicMock() self.intervals = (Interval.Hour, Interval.Day, Interval.Week, Interval.Month, Interval.Year) def test_cpu(self): for interval in self.intervals: self._init_filer() statistics.Statistics(self._filer).cpu(interval) - self._filer.stats.get.assert_called_with(Metric.CPU, params={'interval': interval}) + self._filer.clients.stats.get.assert_called_with(Metric.CPU, params={'interval': interval}) def test_memory(self): self._init_filer() for interval in self.intervals: self._init_filer() statistics.Statistics(self._filer).memory(interval) - self._filer.stats.get.assert_called_with(Metric.Memory, params={'interval': interval}) + self._filer.clients.stats.get.assert_called_with(Metric.Memory, params={'interval': interval}) def test_volume(self): for interval in self.intervals: self._init_filer() statistics.Statistics(self._filer).volume(interval) - self._filer.stats.get.assert_called_with(Metric.Volume, params={'interval': interval}) + self._filer.clients.stats.get.assert_called_with(Metric.Volume, params={'interval': interval}) def test_cache(self): for interval in self.intervals: self._init_filer() statistics.Statistics(self._filer).cache(interval) - self._filer.stats.get.assert_called_with(Metric.Cache, params={'interval': interval}) + self._filer.clients.stats.get.assert_called_with(Metric.Cache, params={'interval': interval}) def test_connections(self): for interval in self.intervals: self._init_filer() statistics.Statistics(self._filer).connections(interval) - self._filer.stats.get.assert_called_with(Metric.Connections, params={'interval': interval}) + self._filer.clients.stats.get.assert_called_with(Metric.Connections, params={'interval': interval}) def test_disk(self): for interval in self.intervals: self._init_filer() statistics.Statistics(self._filer).disk(interval) - self._filer.stats.get.assert_called_with(Metric.Disk, params={'interval': interval}) + self._filer.clients.stats.get.assert_called_with(Metric.Disk, params={'interval': interval}) def test_local_io(self): for interval in self.intervals: self._init_filer() statistics.Statistics(self._filer).local_io(interval) - self._filer.stats.get.assert_called_with(Metric.Local, params={'interval': interval}) + self._filer.clients.stats.get.assert_called_with(Metric.Local, params={'interval': interval}) def test_cloudsync(self): for interval in self.intervals: self._init_filer() statistics.Statistics(self._filer).cloudsync(interval) - self._filer.stats.get.assert_called_with(Metric.CloudSync, params={'interval': interval}) + self._filer.clients.stats.get.assert_called_with(Metric.CloudSync, params={'interval': interval}) From bf8b62b195d8c0cbfb6adae1addeb056c35e18f9 Mon Sep 17 00:00:00 2001 From: Saimon Michelson Date: Tue, 19 May 2026 22:26:12 -0400 Subject: [PATCH 9/9] update to pass lint and ut --- cterasdk/edge/__init__.py | 2 +- cterasdk/edge/remote.py | 2 +- cterasdk/edge/statistics.py | 2 +- cterasdk/objects/synchronous/core.py | 2 +- cterasdk/objects/synchronous/edge.py | 6 +++--- tests/ut/edge/test_statistics.py | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cterasdk/edge/__init__.py b/cterasdk/edge/__init__.py index fb1bf0b1..512b5da3 100644 --- a/cterasdk/edge/__init__.py +++ b/cterasdk/edge/__init__.py @@ -30,7 +30,7 @@ 'shares', 'shell', 'smb', - 'statistics' + 'statistics', 'support', 'sync', 'syslog', diff --git a/cterasdk/edge/remote.py b/cterasdk/edge/remote.py index ebb05850..e5d71c86 100644 --- a/cterasdk/edge/remote.py +++ b/cterasdk/edge/remote.py @@ -14,7 +14,7 @@ def remote_access(device, Portal): logger.info("Enabling remote access. %s", {'tenant': device_tenant, 'device': device_name}) token = authn_token(Portal, device_tenant, device_name) device_object = create_device_object(device) - device_object.sso(token, {Portal._session_id_key: Portal.get_session_id()}) + device_object.sso(token, {Portal._session_id_key: Portal.get_session_id()}) # pylint: disable=protected-access logger.info("Enabled remote access. %s", {'tenant': device_tenant, 'device': device_name}) return device_object diff --git a/cterasdk/edge/statistics.py b/cterasdk/edge/statistics.py index b1625716..9f70a6a9 100644 --- a/cterasdk/edge/statistics.py +++ b/cterasdk/edge/statistics.py @@ -88,4 +88,4 @@ def cloudsync(self, interval): def _statistics(self, metric, interval): return self._edge.clients.stats.get(metric, params={ 'interval': interval - }) \ No newline at end of file + }) diff --git a/cterasdk/objects/synchronous/core.py b/cterasdk/objects/synchronous/core.py index 4e17d342..eb77bee3 100644 --- a/cterasdk/objects/synchronous/core.py +++ b/cterasdk/objects/synchronous/core.py @@ -93,7 +93,7 @@ def context(self): def _session_id_key(self): return 'JSESSIONID' - def get_session_id(self): + def get_session_id(self): # pylint: disable=arguments-differ return super().get_session_id(self.ctera.baseurl) def _authenticator(self, url): diff --git a/cterasdk/objects/synchronous/edge.py b/cterasdk/objects/synchronous/edge.py index e5783c82..46642f98 100644 --- a/cterasdk/objects/synchronous/edge.py +++ b/cterasdk/objects/synchronous/edge.py @@ -153,14 +153,14 @@ def initialized(self): def test(self): return connection.test(self) - def sso(self, ticket, remote): + def sso(self, ticket, session): """ Single Sign on from CTERA Portal to CTERA Edge Filer. :param str ticket: SSO Ticket - :param dict remote: CTERA Portal Session Cookie + :param dict session: CTERA Portal Session Cookie """ - self.default.cookie_jar.update_cookies(remote, self.default.baseurl) + self.default.cookie_jar.update_cookies(session, self.default.baseurl) self._login_object.sso(ticket) self.session().start_session(self) diff --git a/tests/ut/edge/test_statistics.py b/tests/ut/edge/test_statistics.py index c1988972..04e892e5 100644 --- a/tests/ut/edge/test_statistics.py +++ b/tests/ut/edge/test_statistics.py @@ -9,7 +9,7 @@ class TestEdgeStatistics(base_edge.BaseEdgeTest): def setUp(self): super().setUp() - self._filer.clients.clients.stats.get = mock.MagicMock() + self._filer.clients.stats.get = mock.MagicMock() self.intervals = (Interval.Hour, Interval.Day, Interval.Week, Interval.Month, Interval.Year) def test_cpu(self):