SlideShare a Scribd company logo
1 of 24
Download to read offline
Porting checks.py to Actions
03/14/2023 2
Goals of Action Framework
●
Framework for performing pre-PONR Actions
03/14/2023 3
Goals of Action Framework
●
Framework for performing pre-PONR Actions
●
Make each Action more independent
03/14/2023 4
Goals of Action Framework
●
Framework for performing pre-PONR Actions
●
Make each Action more independent
●
One step in any transition to a third party framework (like LEAPP)
03/14/2023 5
Structure
●
Python modules live in convert2rhel/actions/
03/14/2023 6
Structure
●
Python modules live in convert2rhel/actions/
●
Modules contain subclasses of convert2rhel.actions.Action
03/14/2023 7
Structure
●
Python modules live in convert2rhel/actions/
●
Modules contain subclasses of convert2rhel.actions.Action
●
(*) Each subclass will be discovered and run by
convert2rhel.actions.run_actions()
03/14/2023 8
The Action class
●
Action class that inherits from convert2rhel.actions.Action
03/14/2023 9
The Action class
●
Action class that inherits from convert2rhel.actions.Action
●
Several class attributes (set when you define the class)
●
Action.id
●
Action.dependencies
03/14/2023 10
The Action class
●
Action class that inherits from convert2rhel.actions.Action
●
Several class attributes (set when you define the class)
●
Action.id
●
Action.dependencies
●
One required method
●
Action.run()
03/14/2023 11
Porting Checks: Declaration
●
New file for the check
●
Ex: convert2rhel/actions/convert2rhel_latest.py
03/14/2023 12
Porting Checks: Declaration
●
New file for the check
●
Ex: convert2rhel/actions/convert2rhel_latest.py
●
Create a class, name based on the check function name
●
def convert2rhel_latest_check(…)
●
class Convert2rhelLatest(convert2rhel.actions.Action):
03/14/2023 13
Porting Checks: Declaration
●
New file for the check
●
Ex: convert2rhel/actions/convert2rhel_latest.py
●
Create a class, name based on the check function name
●
def convert2rhel_latest_check(…)
●
class Convert2rhelLatest(convert2rhel.actions.Action):
●
Add machine-oriented id
●
Ex: id = “CONVERT2RHEL_LATEST_VERSION”
03/14/2023 14
Porting Checks: Declaration
●
New file for the check
●
Ex: convert2rhel/actions/convert2rhel_latest.py
●
Create a class, name based on the check function name
●
def convert2rhel_latest_check(…)
●
class Convert2rhelLatest(convert2rhel.actions.Action):
●
Add machine-oriented id
●
Ex: id = “CONVERT2RHEL_LATEST_VERSION”
●
Add dependencies if needed
03/14/2023 15
Porting Checks: Function
●
Move code from the check function into the run() method
03/14/2023 16
Porting Checks: Function
●
Move code from the check function into the run() function
●
Replace logger.critical calls with code that sets an error
●
Old: logger.critical(“The running convert2rhel is not the latest version”)
●
New:
self.status = actions.STATUS_CODE[“ERROR”]
self.error_id = “UP_TO_DATE”
self.message = “The running convert2rhel is not the latest version”
return
03/14/2023 17
Porting Checks: Function
●
Move code from the check function into the run() function
●
Replace logger.critical calls with code that sets an error
●
Old: logger.critical(“The running convert2rhel is not the latest version”)
●
New:
self.status = actions.STATUS_CODE[“ERROR”]
self.error_id = “UP_TO_DATE”
self.message = “The running convert2rhel is not the latest version”
return
●
If appropriate, set message on successful cases.
03/14/2023 18
Porting Checks: Function
●
Move code from the check function into the run() function
●
Replace logger.critical calls with code that sets an error
●
Old: logger.critical(“The running convert2rhel is not the latest version”)
●
New:
self.status = actions.STATUS_CODE[“ERROR”]
self.error_id = “UP_TO_DATE”
self.message = “The running convert2rhel is not the latest version”
return
●
If appropriate, set message on successful cases.
●
The Action Runner will take care of displaying the message at the
appropriate time.
03/14/2023 19
Unittests
●
Write a fixture
●
Change how the check/action is invoked
●
Change how to check for errors
03/14/2023 20
Unittests: Fixture
●
Create a fixture that returns an instance of the action
●
@pytest.fixture
def convert2rhel_latest_action():
return convert2rhel_latest.Convert2rhelLatest()
03/14/2023 21
Unittests: Invoking the Action
●
In any test where we ran the check function, use the fixture and
the run() method:
●
def test_convert2rhel_latest_offline(self, caplog, […]):
checks.check_convert2rhel_latest()
●
def test_convert2rhel_latest_offline(
self, caplog, convert2rhel_latest_action, […]):
convert2rhel_latest_action.run()
03/14/2023 22
Unittests: Invoking the Action
●
In any test where we ran the check function, use the fixture and
the run() method:
●
def test_convert2rhel_latest_offline(self, caplog, […]):
checks.check_convert2rhel_latest()
●
def test_convert2rhel_latest_offline(
self, caplog, convert2rhel_latest_action, […]):
convert2rhel_latest_action.run()
03/14/2023 23
Unittests: Checking for errors
●
Where we test for critical errors, switch from pytest.raises and
caplog to checking the status
●
with pytest.raises(SystemExit):
checks.check_convert2rhel_latest()
assert expected_log_msg in caplog.text
●
convert2rhel_latest_check.run()
assert convert2rhel_latest_action.error_id == "OUT_OF_DATE"
assert convert2rhel_latest_action.status ==
actions.STATUS_CODE["ERROR"]
assert expected_log_msg == convert2rhel_latest_action.message
03/14/2023 24
More information
●
Pull Request: https://github.com/oamg/convert2rhel/pull/761
●
Example ported check:
●
convert2rhel/actions/convert2rhel_latest.py
●
convert2rhel/unit_tests/actions/convert2rhel_latest_test.py
●
List of checks to port, see Sub Tasks:
●
https://issues.redhat.com/browse/RHELC-928
●
Ask: Toshio Kuratomi, Rodolfo Olivieri, Preston Watson

More Related Content

Similar to Convert2rhel Development: Porting to the Action Framework

Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6William Marques
 
Guvnor presentation jervis liu
Guvnor presentation jervis liuGuvnor presentation jervis liu
Guvnor presentation jervis liujbossug
 
What's new and what's next in Rudder
What's new and what's next in RudderWhat's new and what's next in Rudder
What's new and what's next in RudderRUDDER
 
State monitoring configuration
State monitoring configurationState monitoring configuration
State monitoring configurationRamnGonzlezRuiz2
 
How Does Kubernetes Build OpenAPI Specifications?
How Does Kubernetes Build OpenAPI Specifications?How Does Kubernetes Build OpenAPI Specifications?
How Does Kubernetes Build OpenAPI Specifications?reallavalamp
 
Java Presentation For Syntax
Java Presentation For SyntaxJava Presentation For Syntax
Java Presentation For SyntaxPravinYalameli
 
Fundamental Concepts of React JS for Beginners.pdf
Fundamental Concepts of React JS for Beginners.pdfFundamental Concepts of React JS for Beginners.pdf
Fundamental Concepts of React JS for Beginners.pdfStephieJohn
 
The Next Step in AS3 Framework Evolution - FITC Amsterdam 2013
The Next Step in AS3 Framework Evolution - FITC Amsterdam 2013The Next Step in AS3 Framework Evolution - FITC Amsterdam 2013
The Next Step in AS3 Framework Evolution - FITC Amsterdam 2013Raimundas Banevičius
 
Yaml as Pipeline GSoC 218 Phase 2 evaluation
Yaml as Pipeline GSoC 218 Phase 2 evaluationYaml as Pipeline GSoC 218 Phase 2 evaluation
Yaml as Pipeline GSoC 218 Phase 2 evaluationAbhishek Gautam
 
Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016
Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016
Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016Dusan Lukic
 
Start with version control and experiments management in machine learning
Start with version control and experiments management in machine learningStart with version control and experiments management in machine learning
Start with version control and experiments management in machine learningMikhail Rozhkov
 
Application of the automation know-how within the EGS-CC project
Application of the automation know-how within the EGS-CC projectApplication of the automation know-how within the EGS-CC project
Application of the automation know-how within the EGS-CC projectNieves Salor
 
Linux Device Driver v3 [Chapter 2]
Linux Device Driver v3 [Chapter 2]Linux Device Driver v3 [Chapter 2]
Linux Device Driver v3 [Chapter 2]Anupam Datta
 
JS Fest 2018. Anna Herlihy. How to Write a Compass Plugin
JS Fest 2018. Anna Herlihy. How to Write a Compass PluginJS Fest 2018. Anna Herlihy. How to Write a Compass Plugin
JS Fest 2018. Anna Herlihy. How to Write a Compass PluginJSFestUA
 
Stateful streaming data pipelines
Stateful streaming data pipelinesStateful streaming data pipelines
Stateful streaming data pipelinesTimothy Farkas
 
Java programming concept
Java programming conceptJava programming concept
Java programming conceptSanjay Gunjal
 
What's New In Python 2.5
What's New In Python 2.5What's New In Python 2.5
What's New In Python 2.5Richard Jones
 

Similar to Convert2rhel Development: Porting to the Action Framework (20)

Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6
 
Guvnor presentation jervis liu
Guvnor presentation jervis liuGuvnor presentation jervis liu
Guvnor presentation jervis liu
 
What's new and what's next in Rudder
What's new and what's next in RudderWhat's new and what's next in Rudder
What's new and what's next in Rudder
 
State monitoring configuration
State monitoring configurationState monitoring configuration
State monitoring configuration
 
How Does Kubernetes Build OpenAPI Specifications?
How Does Kubernetes Build OpenAPI Specifications?How Does Kubernetes Build OpenAPI Specifications?
How Does Kubernetes Build OpenAPI Specifications?
 
Java Presentation For Syntax
Java Presentation For SyntaxJava Presentation For Syntax
Java Presentation For Syntax
 
Sprint 12
Sprint 12Sprint 12
Sprint 12
 
Fundamental Concepts of React JS for Beginners.pdf
Fundamental Concepts of React JS for Beginners.pdfFundamental Concepts of React JS for Beginners.pdf
Fundamental Concepts of React JS for Beginners.pdf
 
The Next Step in AS3 Framework Evolution - FITC Amsterdam 2013
The Next Step in AS3 Framework Evolution - FITC Amsterdam 2013The Next Step in AS3 Framework Evolution - FITC Amsterdam 2013
The Next Step in AS3 Framework Evolution - FITC Amsterdam 2013
 
Yaml as Pipeline GSoC 218 Phase 2 evaluation
Yaml as Pipeline GSoC 218 Phase 2 evaluationYaml as Pipeline GSoC 218 Phase 2 evaluation
Yaml as Pipeline GSoC 218 Phase 2 evaluation
 
Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016
Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016
Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016
 
Start with version control and experiments management in machine learning
Start with version control and experiments management in machine learningStart with version control and experiments management in machine learning
Start with version control and experiments management in machine learning
 
Application of the automation know-how within the EGS-CC project
Application of the automation know-how within the EGS-CC projectApplication of the automation know-how within the EGS-CC project
Application of the automation know-how within the EGS-CC project
 
Linux Device Driver v3 [Chapter 2]
Linux Device Driver v3 [Chapter 2]Linux Device Driver v3 [Chapter 2]
Linux Device Driver v3 [Chapter 2]
 
JS Fest 2018. Anna Herlihy. How to Write a Compass Plugin
JS Fest 2018. Anna Herlihy. How to Write a Compass PluginJS Fest 2018. Anna Herlihy. How to Write a Compass Plugin
JS Fest 2018. Anna Herlihy. How to Write a Compass Plugin
 
Stateful streaming data pipelines
Stateful streaming data pipelinesStateful streaming data pipelines
Stateful streaming data pipelines
 
Java programming concept
Java programming conceptJava programming concept
Java programming concept
 
What's New In Python 2.5
What's New In Python 2.5What's New In Python 2.5
What's New In Python 2.5
 
Java Decompiler
Java DecompilerJava Decompiler
Java Decompiler
 
Open Dayligth usando SDN-NFV
Open Dayligth usando SDN-NFVOpen Dayligth usando SDN-NFV
Open Dayligth usando SDN-NFV
 

Recently uploaded

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 

Recently uploaded (20)

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

Convert2rhel Development: Porting to the Action Framework

  • 2. 03/14/2023 2 Goals of Action Framework ● Framework for performing pre-PONR Actions
  • 3. 03/14/2023 3 Goals of Action Framework ● Framework for performing pre-PONR Actions ● Make each Action more independent
  • 4. 03/14/2023 4 Goals of Action Framework ● Framework for performing pre-PONR Actions ● Make each Action more independent ● One step in any transition to a third party framework (like LEAPP)
  • 5. 03/14/2023 5 Structure ● Python modules live in convert2rhel/actions/
  • 6. 03/14/2023 6 Structure ● Python modules live in convert2rhel/actions/ ● Modules contain subclasses of convert2rhel.actions.Action
  • 7. 03/14/2023 7 Structure ● Python modules live in convert2rhel/actions/ ● Modules contain subclasses of convert2rhel.actions.Action ● (*) Each subclass will be discovered and run by convert2rhel.actions.run_actions()
  • 8. 03/14/2023 8 The Action class ● Action class that inherits from convert2rhel.actions.Action
  • 9. 03/14/2023 9 The Action class ● Action class that inherits from convert2rhel.actions.Action ● Several class attributes (set when you define the class) ● Action.id ● Action.dependencies
  • 10. 03/14/2023 10 The Action class ● Action class that inherits from convert2rhel.actions.Action ● Several class attributes (set when you define the class) ● Action.id ● Action.dependencies ● One required method ● Action.run()
  • 11. 03/14/2023 11 Porting Checks: Declaration ● New file for the check ● Ex: convert2rhel/actions/convert2rhel_latest.py
  • 12. 03/14/2023 12 Porting Checks: Declaration ● New file for the check ● Ex: convert2rhel/actions/convert2rhel_latest.py ● Create a class, name based on the check function name ● def convert2rhel_latest_check(…) ● class Convert2rhelLatest(convert2rhel.actions.Action):
  • 13. 03/14/2023 13 Porting Checks: Declaration ● New file for the check ● Ex: convert2rhel/actions/convert2rhel_latest.py ● Create a class, name based on the check function name ● def convert2rhel_latest_check(…) ● class Convert2rhelLatest(convert2rhel.actions.Action): ● Add machine-oriented id ● Ex: id = “CONVERT2RHEL_LATEST_VERSION”
  • 14. 03/14/2023 14 Porting Checks: Declaration ● New file for the check ● Ex: convert2rhel/actions/convert2rhel_latest.py ● Create a class, name based on the check function name ● def convert2rhel_latest_check(…) ● class Convert2rhelLatest(convert2rhel.actions.Action): ● Add machine-oriented id ● Ex: id = “CONVERT2RHEL_LATEST_VERSION” ● Add dependencies if needed
  • 15. 03/14/2023 15 Porting Checks: Function ● Move code from the check function into the run() method
  • 16. 03/14/2023 16 Porting Checks: Function ● Move code from the check function into the run() function ● Replace logger.critical calls with code that sets an error ● Old: logger.critical(“The running convert2rhel is not the latest version”) ● New: self.status = actions.STATUS_CODE[“ERROR”] self.error_id = “UP_TO_DATE” self.message = “The running convert2rhel is not the latest version” return
  • 17. 03/14/2023 17 Porting Checks: Function ● Move code from the check function into the run() function ● Replace logger.critical calls with code that sets an error ● Old: logger.critical(“The running convert2rhel is not the latest version”) ● New: self.status = actions.STATUS_CODE[“ERROR”] self.error_id = “UP_TO_DATE” self.message = “The running convert2rhel is not the latest version” return ● If appropriate, set message on successful cases.
  • 18. 03/14/2023 18 Porting Checks: Function ● Move code from the check function into the run() function ● Replace logger.critical calls with code that sets an error ● Old: logger.critical(“The running convert2rhel is not the latest version”) ● New: self.status = actions.STATUS_CODE[“ERROR”] self.error_id = “UP_TO_DATE” self.message = “The running convert2rhel is not the latest version” return ● If appropriate, set message on successful cases. ● The Action Runner will take care of displaying the message at the appropriate time.
  • 19. 03/14/2023 19 Unittests ● Write a fixture ● Change how the check/action is invoked ● Change how to check for errors
  • 20. 03/14/2023 20 Unittests: Fixture ● Create a fixture that returns an instance of the action ● @pytest.fixture def convert2rhel_latest_action(): return convert2rhel_latest.Convert2rhelLatest()
  • 21. 03/14/2023 21 Unittests: Invoking the Action ● In any test where we ran the check function, use the fixture and the run() method: ● def test_convert2rhel_latest_offline(self, caplog, […]): checks.check_convert2rhel_latest() ● def test_convert2rhel_latest_offline( self, caplog, convert2rhel_latest_action, […]): convert2rhel_latest_action.run()
  • 22. 03/14/2023 22 Unittests: Invoking the Action ● In any test where we ran the check function, use the fixture and the run() method: ● def test_convert2rhel_latest_offline(self, caplog, […]): checks.check_convert2rhel_latest() ● def test_convert2rhel_latest_offline( self, caplog, convert2rhel_latest_action, […]): convert2rhel_latest_action.run()
  • 23. 03/14/2023 23 Unittests: Checking for errors ● Where we test for critical errors, switch from pytest.raises and caplog to checking the status ● with pytest.raises(SystemExit): checks.check_convert2rhel_latest() assert expected_log_msg in caplog.text ● convert2rhel_latest_check.run() assert convert2rhel_latest_action.error_id == "OUT_OF_DATE" assert convert2rhel_latest_action.status == actions.STATUS_CODE["ERROR"] assert expected_log_msg == convert2rhel_latest_action.message
  • 24. 03/14/2023 24 More information ● Pull Request: https://github.com/oamg/convert2rhel/pull/761 ● Example ported check: ● convert2rhel/actions/convert2rhel_latest.py ● convert2rhel/unit_tests/actions/convert2rhel_latest_test.py ● List of checks to port, see Sub Tasks: ● https://issues.redhat.com/browse/RHELC-928 ● Ask: Toshio Kuratomi, Rodolfo Olivieri, Preston Watson