44import os
55import json
66
7+
78def run (cmd , shell = True , cwd = None ):
89 """
910 Run a command.
@@ -35,7 +36,7 @@ def run_in_context(context, cmd, can_fail=False, expected_exit_code=None, **run_
3536 :return: None
3637 """
3738 if getattr (context , "faketime" , None ) is not None :
38- cmd = ' NO_FAKE_STAT=1 ' + context .faketime + cmd
39+ cmd = " NO_FAKE_STAT=1 " + context .faketime + cmd
3940
4041 if getattr (context , "fake_kernel_release" , None ) is not None :
4142 cmd = context .fake_kernel_release + cmd
@@ -45,19 +46,23 @@ def run_in_context(context, cmd, can_fail=False, expected_exit_code=None, **run_
4546
4647 context .cmd = cmd
4748
48- if hasattr (context .scenario , "working_dir" ) and ' cwd' not in run_args :
49- run_args [' cwd' ] = context .scenario .working_dir
49+ if hasattr (context .scenario , "working_dir" ) and " cwd" not in run_args :
50+ run_args [" cwd" ] = context .scenario .working_dir
5051
5152 context .cmd_exitcode , context .cmd_stdout , context .cmd_stderr = run (cmd , ** run_args )
5253
5354 if not can_fail and context .cmd_exitcode != 0 :
54- raise AssertionError ('Running command "%s" failed: %s' % (cmd , context .cmd_exitcode ))
55+ raise AssertionError (
56+ 'Running command "%s" failed: %s' % (cmd , context .cmd_exitcode )
57+ )
5558 elif expected_exit_code is not None and expected_exit_code != context .cmd_exitcode :
5659 raise AssertionError (
57- 'Running command "%s" had unexpected exit code: %s' % (cmd , context .cmd_exitcode )
60+ 'Running command "%s" had unexpected exit code: %s'
61+ % (cmd , context .cmd_exitcode )
5862 )
5963
60- @given ('system is registered against candlepin server' )
64+
65+ @given ("system is registered against candlepin server" )
6166def step_impl (context ):
6267 """
6368 Check if the system is registered against the candlepin server. If not, register it.
@@ -71,7 +76,8 @@ def step_impl(context):
7176 cmd = "rhc connect --username admin --password admin --organization donaldduck"
7277 run_in_context (context , cmd , can_fail = False )
7378
74- @given ('repositories are enabled' )
79+
80+ @given ("repositories are enabled" )
7581def step_impl (context ):
7682 """
7783 Enable repositories for the system.
@@ -82,6 +88,7 @@ def step_impl(context):
8288 cmd = f"dnf5 config-manager setopt { row ['repo_id' ]} .enabled=1"
8389 run_in_context (context , cmd , can_fail = False )
8490
91+
8592@when ('rpm "{rpm_name}" is installed from RPM repository' )
8693def step_impl (context , rpm_name ):
8794 """
@@ -93,7 +100,10 @@ def step_impl(context, rpm_name):
93100 cmd = f"dnf5 install -y { rpm_name } "
94101 run_in_context (context , cmd , can_fail = False )
95102
96- @then ('productid certificate "{product_cert_name}" is installed in "{product_cert_dir_path}"' )
103+
104+ @then (
105+ 'productid certificate "{product_cert_name}" is installed in "{product_cert_dir_path}"'
106+ )
97107def step_impl (context , product_cert_name , product_cert_dir_path ):
98108 """
99109 Check if the productid certificate is installed in the specified directory.
@@ -103,4 +113,29 @@ def step_impl(context, product_cert_name, product_cert_dir_path):
103113 :return: None
104114 """
105115 product_cert_path = os .path .join (product_cert_dir_path , product_cert_name )
106- assert os .path .exists (product_cert_path )
116+ assert os .path .exists (product_cert_path )
117+
118+
119+ PRODUCTDB_PATH = "/var/lib/rhsm/productid.json"
120+
121+
122+ @then ("product database contains" )
123+ def step_impl (contex ):
124+ """
125+ Check if the product database contains the expected products and repositories.
126+ :param contex: behave context
127+ :return: None
128+ """
129+ productdb_content = None
130+ assert os .path .exists (PRODUCTDB_PATH )
131+ with open (PRODUCTDB_PATH ) as f :
132+ productdb_content = json .loads (f .read ())
133+
134+ assert productdb_content is not None
135+ assert isinstance (productdb_content , dict )
136+ for row in contex .table :
137+ product_id = row ["product_id" ]
138+ repo_id = row ["repo_id" ]
139+ assert product_id in productdb_content
140+ repo_list = productdb_content [product_id ]
141+ assert repo_id in repo_list
0 commit comments