Skip to content

Commit

Permalink
remove the deprecated std resources from the codebase. (Issue #7356, PR
Browse files Browse the repository at this point in the history
#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)
  • Loading branch information
FloLey authored and inmantaci committed May 13, 2024
1 parent 1841bba commit 33bc2cb
Show file tree
Hide file tree
Showing 30 changed files with 827 additions and 614 deletions.
4 changes: 4 additions & 0 deletions changelogs/unreleased/7356-remove-deprecated-std.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
description: remove the deprecated std resources from the codebase.
issue-nr: 7356
change-type: patch
destination-branches: [iso6]
2 changes: 1 addition & 1 deletion src/inmanta/agent/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class provider: # noqa: N801
A decorator that registers a new handler.
:param resource_type: The type of the resource this handler provides an implementation for.
For example, :inmanta:entity:`std::File`
For example, :inmanta:entity:`std::testing::NullResource`
:param name: A name to reference this provider.
"""

Expand Down
13 changes: 10 additions & 3 deletions src/inmanta/ast/statements/assign.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,17 @@ def __repr__(self) -> str:

class ShortIndexLookup(IndexLookup):
"""lookup of the form
vm = ip::Host(...)
file = std::File(host=vm, path="/etc/motd", ...)
entity ExtendedHost extends ip::Host:
end
vm.files[path="/etc/motd"]
ExtendedHost.resources [0:] -- std::testing::NullResource.host[1]
host = ExtendedHost(...)
resource = std::testing::NullResource(name='test', host=host, ...)
index std::testing::NullResource(host, name)
host.resources[name="test"]
"""

__slots__ = ("rootobject", "relation", "querypart", "wrapped_querypart")
Expand Down
6 changes: 4 additions & 2 deletions src/inmanta/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ class CodeManager:
"""This class is responsible for loading and packaging source code for types (resources, handlers, ...) that need to be
available in a remote process (e.g. agent).
__type_file: Maps Inmanta type names (e.g., ``std::File``, ``mymodule::Mytype``) to sets of filenames containing
__type_file: Maps Inmanta type names (e.g., ``std::testing::NullResource``, ``mymodule::Mytype``)
to sets of filenames containing
the necessary source code (all plugin files in the module).
__file_info: Stores metadata about each individual source code file. The keys are file paths and the values
in this dictionary are ``SourceInfo`` objects.
Expand All @@ -130,7 +131,8 @@ def __init__(self) -> None:
def register_code(self, type_name: str, instance: object) -> None:
"""Register the given type_object under the type_name and register the source associated with this type object.
:param type_name: The inmanta type name for which the source of type_object will be registered. For example std::File
:param type_name: The inmanta type name for which the source of type_object will be registered.
For example std::testing::NullResource
:param instance: An instance for which the code needs to be registered.
"""
file_name = self.get_object_source(instance)
Expand Down
2 changes: 1 addition & 1 deletion src/inmanta/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class resource: # noqa: N801
:class:`~inmanta.resources.Resource`
:param name: The name of the entity in the configuration model it creates a resources from. For example
:inmanta:entity:`std::File`
:inmanta:entity:`std::testing::NullResource`
:param id_attribute: The attribute of `this` resource that uniquely identifies a resource on an agent. This attribute
can be mapped.
:param agent: This string indicates how the agent of this resource is determined. This string points to an attribute,
Expand Down
16 changes: 8 additions & 8 deletions tests/compiler/test_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
def test_str_on_instance_pos(snippetcompiler):
snippetcompiler.setup_for_snippet(
"""
import std
import std::testing
entity Hg:
end
Expand All @@ -47,19 +47,19 @@ def test_str_on_instance_pos(snippetcompiler):
for i in hg.hosts:
std::ConfigFile(host=i, path="/fx", content="")
std::testing::NullResource(name=i.name)
end
"""
)
(types, _) = compiler.do_compile()
files = types["std::File"].get_all_instances()
assert len(files) == 3
test_resources = types["std::testing::NullResource"].get_all_instances()
assert len(test_resources) == 3


def test_str_on_instance_neg(snippetcompiler):
snippetcompiler.setup_for_snippet(
"""
import std
import std::testing
entity Hg:
end
Expand All @@ -76,13 +76,13 @@ def test_str_on_instance_neg(snippetcompiler):
for i in hg.hosts:
std::ConfigFile(host=i, path="/fx", content="")
std::testing::NullResource(name=i.name)
end
"""
)
(types, _) = compiler.do_compile()
files = types["std::File"].get_all_instances()
assert len(files) == 1
test_resources = types["std::testing::NullResource"].get_all_instances()
assert len(test_resources) == 1


def test_implements_inheritance(snippetcompiler):
Expand Down
17 changes: 14 additions & 3 deletions tests/compiler/test_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,23 @@
def test_issue_127_default_overrides(snippetcompiler):
snippetcompiler.setup_for_snippet(
"""
f1=std::ConfigFile(host=std::Host(name="jos",os=std::linux), path="/tmp/test", owner="wouter", content="blabla")
import std::testing
entity NullResourceBis extends std::testing::NullResource:
string agentname ="agentbis"
end
implementation a for NullResourceBis:
end
implement NullResourceBis using a
f1=NullResourceBis(name="test", agentname="agent")
"""
)
(types, _) = compiler.do_compile()
instances = types["std::File"].get_all_instances()
assert instances[0].get_attribute("owner").get_value() == "wouter"
instances = types["__config__::NullResourceBis"].get_all_instances()
assert instances[0].get_attribute("agentname").get_value() == "agent"


def test_issue_135_duplo_relations(snippetcompiler):
Expand Down
53 changes: 20 additions & 33 deletions tests/compiler/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,8 @@
import pytest

import inmanta.compiler as compiler
from inmanta.ast import (
DuplicateException,
IndexException,
NotFoundException,
RuntimeException,
TypeNotFoundException,
TypingException,
)
from inmanta.ast.statements.generator import IndexCollisionException
from inmanta.ast import DuplicateException, IndexException, NotFoundException, RuntimeException, TypeNotFoundException
from inmanta.ast.statements.generator import IndexAttributeMissingInConstructorException, IndexCollisionException
from inmanta.compiler.help.explainer import ExplainerFactory


Expand All @@ -49,39 +42,29 @@ def test_issue_121_non_matching_index(snippetcompiler):
def test_issue_122_index_inheritance(snippetcompiler):
snippetcompiler.setup_for_snippet(
"""
entity Repository extends std::File:
entity TopResource:
string name
bool gpgcheck=false
bool enabled=true
string baseurl
string gpgkey=""
int metadata_expire=7200
bool send_event=true
end
implementation redhatRepo for Repository:
self.mode = 644
self.owner = "root"
self.group = "root"
index TopResource(name)
self.path = "/etc/yum.repos.d/{{ name }}.repo"
self.content = "{{name}}"
entity TestResource extends TopResource:
bool enabled=true
end
implement Repository using redhatRepo
implementation testRes for TestResource:
self.name="test"
end
h1 = std::Host(name="test", os=std::linux)
implement TestResource using testRes
Repository(host=h1, name="demo", baseurl="http://example.com")
Repository(host=h1, name="demo", baseurl="http://example.com")
TestResource()
"""
)

try:
with pytest.raises(IndexAttributeMissingInConstructorException) as e:
compiler.do_compile()
raise AssertionError("Should get exception")
except TypingException as e:
assert e.location.lnr == 25
assert e.value.location.lnr == 18


def test_issue_140_index_error(snippetcompiler):
Expand Down Expand Up @@ -190,9 +173,13 @@ def test_index_on_subtype(snippetcompiler):
def test_index_on_subtype2(snippetcompiler):
snippetcompiler.setup_for_snippet(
"""
host = std::Host(name="a",os=std::linux)
a=std::DefaultDirectory(host=host,path="/etc")
b=std::Directory(host=host,path="/etc",mode=755 ,group="root",owner="root" )
import std::testing
entity NullResourceBis extends std::testing::NullResource:
end
a=std::testing::NullResource(name="test", agentname="agent1", fail=false)
b=NullResourceBis(name="test", agentname="agent1")
"""
)
with pytest.raises(DuplicateException):
Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_list_atributes(snippetcompiler):
"""
entity Jos:
bool[] bar
std::package_state[] ips = ["installed"]
std::email_str[] ips = ["aaa@aaa.com"]
string[] floom = []
string[] floomx = ["a", "b"]
string box = "a"
Expand All @@ -45,7 +45,7 @@ def test_list_atributes(snippetcompiler):
)
(_, root) = compiler.do_compile()

def check_jos(jos, bar, ips=["installed"], floom=[], floomx=["a", "b"], box="a"):
def check_jos(jos, bar, ips=["aaa@aaa.com"], floom=[], floomx=["a", "b"], box="a"):
jos = jos.get_value()
assert jos.get_attribute("bar").get_value() == bar
assert jos.get_attribute("ips").get_value(), ips
Expand Down
22 changes: 12 additions & 10 deletions tests/compiler/test_relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,37 +473,39 @@ def test_set_wrong_relation_type(snippetcompiler):
# noqa: E501
snippetcompiler.setup_for_error(
"""
import std::testing
entity Credentials:
end
Credentials.file [1] -- std::File
Credentials.null_resource [1] -- std::testing::NullResource
implement Credentials using std::none
creds = Credentials(file=creds)
creds = Credentials(null_resource=creds)
""",
"""Could not set attribute `file` on instance `__config__::Credentials (instantiated at {dir}/main.cf:9)`"""
""" (reported in Construct(Credentials) ({dir}/main.cf:9))
"""Could not set attribute `null_resource` on instance `__config__::Credentials (instantiated at {dir}/main.cf:10)`"""
""" (reported in Construct(Credentials) ({dir}/main.cf:10))
caused by:
Invalid class type for __config__::Credentials (instantiated at {dir}/main.cf:9), should be std::File """
"""(reported in Construct(Credentials) ({dir}/main.cf:9))""",
Invalid class type for __config__::Credentials (instantiated at {dir}/main.cf:10), should be std::testing::NullResource """
"""(reported in Construct(Credentials) ({dir}/main.cf:10))""",
)

snippetcompiler.setup_for_error(
"""
import std::testing
entity Credentials:
end
Credentials.file [1] -- std::File
Credentials.null_resource [1] -- std::testing::NullResource
implement Credentials using std::none
creds = Credentials()
creds.file = creds
creds.null_resource = creds
""",
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))
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))
caused by:
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
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
)


Expand Down
17 changes: 10 additions & 7 deletions tests/compiler/test_requires.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,12 @@ def test_abstract_requires_2(snippetcompiler, caplog):
def test_issue_220_dep_loops(snippetcompiler):
snippetcompiler.setup_for_snippet(
"""
import std
import std::testing
host = std::Host(name="Test", os=std::unix)
f1 = std::ConfigFile(host=host, path="/f1", content="")
f2 = std::ConfigFile(host=host, path="/f2", content="")
f3 = std::ConfigFile(host=host, path="/f3", content="")
f4 = std::ConfigFile(host=host, path="/f4", content="")
f1 = std::testing::NullResource(name="f1")
f2 = std::testing::NullResource(name="f2")
f3 = std::testing::NullResource(name="f3")
f4 = std::testing::NullResource(name="f4")
f1.requires = f2
f2.requires = f3
f3.requires = f1
Expand All @@ -143,4 +142,8 @@ def test_issue_220_dep_loops(snippetcompiler):
snippetcompiler.do_export()

cyclenames = [r.id.resource_str() for r in e.value.cycle]
assert set(cyclenames) == {"std::File[Test,path=/f3]", "std::File[Test,path=/f2]", "std::File[Test,path=/f1]"}
assert set(cyclenames) == {
"std::testing::NullResource[internal,name=f1]",
"std::testing::NullResource[internal,name=f2]",
"std::testing::NullResource[internal,name=f3]",
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
entity NullResourceBis extends ManagedResource, PurgeableResource:
"""
A resource that does nothing, for use in tests and examples

:attr name: the name of this resource
:attr agentname: the name of the agent to deploy this resource on
:attr fail: when true, this resource will always fail on both dryrun and deploy
"""
string name = "null"
string agentname = "internal"
bool send_event = true
bool fail = false
end

index NullResourceBis(agentname, name)

implement NullResourceBis using std::none
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
from inmanta_plugins.multiple_plugin_files.helpers import helper


@provider("std::Directory", name="myhandler")
@provider("multiple_plugin_files::NullResourceBis", name="myhandler")
class MyHandler(ResourceHandler):
pass
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from inmanta.agent.handler import ResourceHandler, provider


@provider("std::File", name="myhandler")
@provider("std::testing::NullResource", name="myhandler")
class MyHandler(ResourceHandler):
pass
Loading

0 comments on commit 33bc2cb

Please sign in to comment.