Skip to content

Commit 33bc2cb

Browse files
FloLeyinmantaci
authored andcommitted
remove the deprecated std resources from the codebase. (Issue #7356, PR #7610)
# Description drop all usages of deprecated std resources from core test (https://github.com/suite/inmanta-core/issues/7356) # Self Check: Strike through any lines that are not applicable (`~~line~~`) then check the box - [x] Attached issue to pull request - [x] Changelog entry - [x] Type annotations are present - [x] Code is clear and sufficiently documented - [x] No (preventable) type errors (check using make mypy or make mypy-diff) - [x] Sufficient test cases (reproduces the bug/tests the requested feature) - [x] Correct, in line with design - [ ] End user documentation is included or an issue is created for end-user documentation (add ref to issue here: ) - [ ] If this PR fixes a race condition in the test suite, also push the fix to the relevant stable branche(s) (see [test-fixes](https://internal.inmanta.com/development/core/tasks/build-master.html#test-fixes) for more info)
1 parent 1841bba commit 33bc2cb

30 files changed

+827
-614
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
description: remove the deprecated std resources from the codebase.
2+
issue-nr: 7356
3+
change-type: patch
4+
destination-branches: [iso6]

src/inmanta/agent/handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class provider: # noqa: N801
5656
A decorator that registers a new handler.
5757
5858
:param resource_type: The type of the resource this handler provides an implementation for.
59-
For example, :inmanta:entity:`std::File`
59+
For example, :inmanta:entity:`std::testing::NullResource`
6060
:param name: A name to reference this provider.
6161
"""
6262

src/inmanta/ast/statements/assign.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -480,10 +480,17 @@ def __repr__(self) -> str:
480480

481481
class ShortIndexLookup(IndexLookup):
482482
"""lookup of the form
483-
vm = ip::Host(...)
484-
file = std::File(host=vm, path="/etc/motd", ...)
483+
entity ExtendedHost extends ip::Host:
484+
end
485485
486-
vm.files[path="/etc/motd"]
486+
ExtendedHost.resources [0:] -- std::testing::NullResource.host[1]
487+
488+
host = ExtendedHost(...)
489+
resource = std::testing::NullResource(name='test', host=host, ...)
490+
491+
index std::testing::NullResource(host, name)
492+
493+
host.resources[name="test"]
487494
"""
488495

489496
__slots__ = ("rootobject", "relation", "querypart", "wrapped_querypart")

src/inmanta/loader.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ class CodeManager:
117117
"""This class is responsible for loading and packaging source code for types (resources, handlers, ...) that need to be
118118
available in a remote process (e.g. agent).
119119
120-
__type_file: Maps Inmanta type names (e.g., ``std::File``, ``mymodule::Mytype``) to sets of filenames containing
120+
__type_file: Maps Inmanta type names (e.g., ``std::testing::NullResource``, ``mymodule::Mytype``)
121+
to sets of filenames containing
121122
the necessary source code (all plugin files in the module).
122123
__file_info: Stores metadata about each individual source code file. The keys are file paths and the values
123124
in this dictionary are ``SourceInfo`` objects.
@@ -130,7 +131,8 @@ def __init__(self) -> None:
130131
def register_code(self, type_name: str, instance: object) -> None:
131132
"""Register the given type_object under the type_name and register the source associated with this type object.
132133
133-
:param type_name: The inmanta type name for which the source of type_object will be registered. For example std::File
134+
:param type_name: The inmanta type name for which the source of type_object will be registered.
135+
For example std::testing::NullResource
134136
:param instance: An instance for which the code needs to be registered.
135137
"""
136138
file_name = self.get_object_source(instance)

src/inmanta/resources.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class resource: # noqa: N801
5151
:class:`~inmanta.resources.Resource`
5252
5353
:param name: The name of the entity in the configuration model it creates a resources from. For example
54-
:inmanta:entity:`std::File`
54+
:inmanta:entity:`std::testing::NullResource`
5555
:param id_attribute: The attribute of `this` resource that uniquely identifies a resource on an agent. This attribute
5656
can be mapped.
5757
:param agent: This string indicates how the agent of this resource is determined. This string points to an attribute,

tests/compiler/test_basics.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
def test_str_on_instance_pos(snippetcompiler):
3131
snippetcompiler.setup_for_snippet(
3232
"""
33-
import std
33+
import std::testing
3434
3535
entity Hg:
3636
end
@@ -47,19 +47,19 @@ def test_str_on_instance_pos(snippetcompiler):
4747
4848
4949
for i in hg.hosts:
50-
std::ConfigFile(host=i, path="/fx", content="")
50+
std::testing::NullResource(name=i.name)
5151
end
5252
"""
5353
)
5454
(types, _) = compiler.do_compile()
55-
files = types["std::File"].get_all_instances()
56-
assert len(files) == 3
55+
test_resources = types["std::testing::NullResource"].get_all_instances()
56+
assert len(test_resources) == 3
5757

5858

5959
def test_str_on_instance_neg(snippetcompiler):
6060
snippetcompiler.setup_for_snippet(
6161
"""
62-
import std
62+
import std::testing
6363
6464
entity Hg:
6565
end
@@ -76,13 +76,13 @@ def test_str_on_instance_neg(snippetcompiler):
7676
7777
7878
for i in hg.hosts:
79-
std::ConfigFile(host=i, path="/fx", content="")
79+
std::testing::NullResource(name=i.name)
8080
end
8181
"""
8282
)
8383
(types, _) = compiler.do_compile()
84-
files = types["std::File"].get_all_instances()
85-
assert len(files) == 1
84+
test_resources = types["std::testing::NullResource"].get_all_instances()
85+
assert len(test_resources) == 1
8686

8787

8888
def test_implements_inheritance(snippetcompiler):

tests/compiler/test_defaults.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,23 @@
2626
def test_issue_127_default_overrides(snippetcompiler):
2727
snippetcompiler.setup_for_snippet(
2828
"""
29-
f1=std::ConfigFile(host=std::Host(name="jos",os=std::linux), path="/tmp/test", owner="wouter", content="blabla")
29+
import std::testing
30+
31+
entity NullResourceBis extends std::testing::NullResource:
32+
string agentname ="agentbis"
33+
end
34+
35+
implementation a for NullResourceBis:
36+
end
37+
38+
implement NullResourceBis using a
39+
40+
f1=NullResourceBis(name="test", agentname="agent")
3041
"""
3142
)
3243
(types, _) = compiler.do_compile()
33-
instances = types["std::File"].get_all_instances()
34-
assert instances[0].get_attribute("owner").get_value() == "wouter"
44+
instances = types["__config__::NullResourceBis"].get_all_instances()
45+
assert instances[0].get_attribute("agentname").get_value() == "agent"
3546

3647

3748
def test_issue_135_duplo_relations(snippetcompiler):

tests/compiler/test_index.py

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,8 @@
2020
import pytest
2121

2222
import inmanta.compiler as compiler
23-
from inmanta.ast import (
24-
DuplicateException,
25-
IndexException,
26-
NotFoundException,
27-
RuntimeException,
28-
TypeNotFoundException,
29-
TypingException,
30-
)
31-
from inmanta.ast.statements.generator import IndexCollisionException
23+
from inmanta.ast import DuplicateException, IndexException, NotFoundException, RuntimeException, TypeNotFoundException
24+
from inmanta.ast.statements.generator import IndexAttributeMissingInConstructorException, IndexCollisionException
3225
from inmanta.compiler.help.explainer import ExplainerFactory
3326

3427

@@ -49,39 +42,29 @@ def test_issue_121_non_matching_index(snippetcompiler):
4942
def test_issue_122_index_inheritance(snippetcompiler):
5043
snippetcompiler.setup_for_snippet(
5144
"""
52-
entity Repository extends std::File:
45+
entity TopResource:
5346
string name
54-
bool gpgcheck=false
55-
bool enabled=true
56-
string baseurl
57-
string gpgkey=""
58-
int metadata_expire=7200
59-
bool send_event=true
6047
end
6148
62-
implementation redhatRepo for Repository:
63-
self.mode = 644
64-
self.owner = "root"
65-
self.group = "root"
49+
index TopResource(name)
6650
67-
self.path = "/etc/yum.repos.d/{{ name }}.repo"
68-
self.content = "{{name}}"
51+
entity TestResource extends TopResource:
52+
bool enabled=true
6953
end
7054
71-
implement Repository using redhatRepo
55+
implementation testRes for TestResource:
56+
self.name="test"
57+
end
7258
73-
h1 = std::Host(name="test", os=std::linux)
59+
implement TestResource using testRes
7460
75-
Repository(host=h1, name="demo", baseurl="http://example.com")
76-
Repository(host=h1, name="demo", baseurl="http://example.com")
61+
TestResource()
7762
"""
7863
)
7964

80-
try:
65+
with pytest.raises(IndexAttributeMissingInConstructorException) as e:
8166
compiler.do_compile()
82-
raise AssertionError("Should get exception")
83-
except TypingException as e:
84-
assert e.location.lnr == 25
67+
assert e.value.location.lnr == 18
8568

8669

8770
def test_issue_140_index_error(snippetcompiler):
@@ -190,9 +173,13 @@ def test_index_on_subtype(snippetcompiler):
190173
def test_index_on_subtype2(snippetcompiler):
191174
snippetcompiler.setup_for_snippet(
192175
"""
193-
host = std::Host(name="a",os=std::linux)
194-
a=std::DefaultDirectory(host=host,path="/etc")
195-
b=std::Directory(host=host,path="/etc",mode=755 ,group="root",owner="root" )
176+
import std::testing
177+
178+
entity NullResourceBis extends std::testing::NullResource:
179+
end
180+
181+
a=std::testing::NullResource(name="test", agentname="agent1", fail=false)
182+
b=NullResourceBis(name="test", agentname="agent1")
196183
"""
197184
)
198185
with pytest.raises(DuplicateException):

tests/compiler/test_list.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def test_list_atributes(snippetcompiler):
2828
"""
2929
entity Jos:
3030
bool[] bar
31-
std::package_state[] ips = ["installed"]
31+
std::email_str[] ips = ["[email protected]"]
3232
string[] floom = []
3333
string[] floomx = ["a", "b"]
3434
string box = "a"
@@ -45,7 +45,7 @@ def test_list_atributes(snippetcompiler):
4545
)
4646
(_, root) = compiler.do_compile()
4747

48-
def check_jos(jos, bar, ips=["installed"], floom=[], floomx=["a", "b"], box="a"):
48+
def check_jos(jos, bar, ips=["[email protected]"], floom=[], floomx=["a", "b"], box="a"):
4949
jos = jos.get_value()
5050
assert jos.get_attribute("bar").get_value() == bar
5151
assert jos.get_attribute("ips").get_value(), ips

tests/compiler/test_relations.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -473,37 +473,39 @@ def test_set_wrong_relation_type(snippetcompiler):
473473
# noqa: E501
474474
snippetcompiler.setup_for_error(
475475
"""
476+
import std::testing
476477
entity Credentials:
477478
end
478479
479-
Credentials.file [1] -- std::File
480+
Credentials.null_resource [1] -- std::testing::NullResource
480481
481482
implement Credentials using std::none
482483
483-
creds = Credentials(file=creds)
484+
creds = Credentials(null_resource=creds)
484485
""",
485-
"""Could not set attribute `file` on instance `__config__::Credentials (instantiated at {dir}/main.cf:9)`"""
486-
""" (reported in Construct(Credentials) ({dir}/main.cf:9))
486+
"""Could not set attribute `null_resource` on instance `__config__::Credentials (instantiated at {dir}/main.cf:10)`"""
487+
""" (reported in Construct(Credentials) ({dir}/main.cf:10))
487488
caused by:
488-
Invalid class type for __config__::Credentials (instantiated at {dir}/main.cf:9), should be std::File """
489-
"""(reported in Construct(Credentials) ({dir}/main.cf:9))""",
489+
Invalid class type for __config__::Credentials (instantiated at {dir}/main.cf:10), should be std::testing::NullResource """
490+
"""(reported in Construct(Credentials) ({dir}/main.cf:10))""",
490491
)
491492

492493
snippetcompiler.setup_for_error(
493494
"""
495+
import std::testing
494496
entity Credentials:
495497
end
496498
497-
Credentials.file [1] -- std::File
499+
Credentials.null_resource [1] -- std::testing::NullResource
498500
499501
implement Credentials using std::none
500502
501503
creds = Credentials()
502-
creds.file = creds
504+
creds.null_resource = creds
503505
""",
504-
r"""Could not set attribute `file` on instance `__config__::Credentials (instantiated at {dir}/main.cf:9)` (reported in creds.file = creds ({dir}/main.cf:10))
506+
r"""Could not set attribute `null_resource` on instance `__config__::Credentials (instantiated at {dir}/main.cf:10)` (reported in creds.null_resource = creds ({dir}/main.cf:11))
505507
caused by:
506-
Invalid class type for __config__::Credentials (instantiated at {dir}/main.cf:9), should be std::File (reported in creds.file = creds ({dir}/main.cf:10))""", # noqa: E501
508+
Invalid class type for __config__::Credentials (instantiated at {dir}/main.cf:10), should be std::testing::NullResource (reported in creds.null_resource = creds ({dir}/main.cf:11))""", # noqa: E501
507509
)
508510

509511

0 commit comments

Comments
 (0)