Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Oxidized::String): implement Oxidized::String using refinements a… #2750

Merged

Conversation

aschaber1
Copy link
Collaborator

@aschaber1 aschaber1 commented Apr 14, 2023

…nd adding them to comware as PoC

Closes: #2749

Pre-Request Checklist

  • Passes rubocop code analysis (try rubocop --auto-correct)
  • Tests added or adapted (try rake test)
  • Changes are reflected in the documentation
  • User-visible changes appended to CHANGELOG.md

Description

@aschaber1 aschaber1 force-pushed the 2749-comware-issues-with-cut_both-in-0290 branch from e3d5c1f to c1943dd Compare April 14, 2023 07:46
@codecov-commenter
Copy link

codecov-commenter commented Apr 14, 2023

Codecov Report

Patch coverage: 35.71% and project coverage change: -46.46 ⚠️

Comparison is base (637434b) 66.40% compared to head (8575690) 19.94%.

❗ Current head 8575690 differs from pull request most recent head e47d719. Consider uploading reports for the commit e47d719 to get more accurate results

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@             Coverage Diff             @@
##           master    #2750       +/-   ##
===========================================
- Coverage   66.40%   19.94%   -46.46%     
===========================================
  Files          30       13       -17     
  Lines        1500      692      -808     
===========================================
- Hits          996      138      -858     
- Misses        504      554       +50     
Impacted Files Coverage Δ
lib/oxidized/model/model.rb 1.72% <0.00%> (-75.87%) ⬇️
lib/refinements.rb 40.00% <40.00%> (ø)
lib/oxidized/model/outputs.rb 4.54% <50.00%> (-65.46%) ⬇️
lib/oxidized.rb 33.33% <100.00%> (-60.61%) ⬇️

... and 22 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@aschaber1 aschaber1 force-pushed the 2749-comware-issues-with-cut_both-in-0290 branch 3 times, most recently from f119ac8 to e36a210 Compare April 14, 2023 11:30
@neilschelly
Copy link
Contributor

I tried running this to verify the fix for Issue #2749 , but it crashed out at the first attempt to scrape a config from a JunOS device. Now , it's not finding a type method for String objects.
-N

cat crash
--------------------------------------------------
2023-04-14 11:29:00 UTC
undefined method `type' for "# fpc0:
# --------------------------------------------------------------------------
# Hostname: che-acc1-sw
# Model: ex4300-48mp
# Junos: 20.4R3-S1.3
# JUNOS OS Kernel 64-bit  [20210909.a3fd70d_builder_stable_11-204ab]
# JUNOS OS libs [20210909.a3fd70d_builder_stable_11-204ab]
# JUNOS OS runtime [20210909.a3fd70d_builder_stable_11-204ab]
# JUNOS OS time zone information [20210909.a3fd70d_builder_stable_11-204ab]
# JUNOS OS libs compat32 [20210909.a3fd70d_builder_stable_11-204ab]
# JUNOS OS 32-bit compatibility [20210909.a3fd70d_builder_stable_11-204ab]
# JUNOS py extensions2 [20211120.090111_builder_junos_204_r3_s1]
# JUNOS py extensions [20211120.090111_builder_junos_204_r3_s1]
# JUNOS py base2 [20211120.090111_builder_junos_204_r3_s1]
# JUNOS py base [20211120.090111_builder_junos_204_r3_s1]
# JUNOS OS vmguest [20210909.a3fd70d_builder_stable_11-204ab]
# JUNOS OS crypto [20210909.a3fd70d_builder_stable_11-204ab]
# JUNOS OS boot-ve files [20210909.a3fd70d_builder_stable_11-204ab]
# JUNOS network stack and utilities [20211120.090111_builder_junos_204_r3_s1]
# JUNOS libs [20211120.090111_builder_junos_204_r3_s1]
# JUNOS libs compat32 [20211120.090111_builder_junos_204_r3_s1]
# JUNOS runtime [20211120.090111_builder_junos_204_r3_s1]
# JUNOS na telemetry [20.4R3-S1.3]
# JUNOS Web Management Platform Package [20211120.090111_builder_junos_204_r3_s1]
# JUNOS qfx modules [20211120.090111_builder_junos_204_r3_s1]
# JUNOS qfx runtime [20211120.090111_builder_junos_204_r3_s1]
# JUNOS probe utility [20211120.090111_builder_junos_204_r3_s1]
# JUNOS common platform support [20211120.090111_builder_junos_204_r3_s1]
# JUNOS qfx platform support [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Openconfig [20.4R3-S1.3]
# JUNOS dcp network modules [20211120.090111_builder_junos_204_r3_s1]
# JUNOS modules [20211120.090111_builder_junos_204_r3_s1]
# JUNOS qfx Data Plane Crypto Support [20211120.090111_builder_junos_204_r3_s1]
# JUNOS daemons [20211120.090111_builder_junos_204_r3_s1]
# JUNOS qfx daemons [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services URL Filter package [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services TLB Service PIC package [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services Telemetry [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services TCP-LOG [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services SSL [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services SOFTWIRE [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services Stateful Firewall [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services RTCOM [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services RPM [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services PCEF package [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services NAT [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services Mobile Subscriber Service Container package [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services MobileNext Software package [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services Logging Report Framework package [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services LL-PDF Container package [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services Jflow Container package [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services Deep Packet Inspection package [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services IPSec [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services IDS [20211120.090111_builder_junos_204_r3_s1]
# JUNOS IDP Services [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services HTTP Content Management package [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services Crypto [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services Captive Portal and Content Delivery Container package [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services COS [20211120.090111_builder_junos_204_r3_s1]
# JUNOS AppId Services [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services Application Level Gateways [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services AACL Container package [20211120.090111_builder_junos_204_r3_s1]
# JUNOS SDN Software Suite [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Extension Toolkit [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Phone-home [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Packet Forwarding Engine Support (DC-PFE) [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Packet Forwarding Engine Support (M/T Common) [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Juniper Malware Removal Tool (JMRT) [1.0.0+20211120.090111_builder_junos_204_r3_s1]
# JUNOS J-Insight [20211120.090111_builder_junos_204_r3_s1]
# JUNOS jfirmware [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Online Documentation [20211120.090111_builder_junos_204_r3_s1]
# JUNOS jail runtime [20210909.a3fd70d_builder_stable_11-204ab]
# JUNOS FIPS mode utilities [20211120.090111_builder_junos_204_r3_s1]
# Junos host: 20.4R3-S1.3
# JUNOS Host kernel-release [3.14.52-rt50-WR7.0.0.9_ovp]
# JUNOS Host kernel-version [#1 SMP Mon Oct 18 05:48:26 PDT 2021]
# JUNOS Host ex-4300mp platform package [20.4R3-S1.3]
# JUNOS Host ex-4300mp control-plane package [20.4R3-S1.3]
# JUNOS Host ex-4300mp base package [20.4R3-S1.3]
# JUNOS Host ex-4300mp data-plane package [20.4R3-S1.3]
# 
# localre:
# --------------------------------------------------------------------------
# Hostname: che-acc1-sw
# Model: ex4300-48mp
# Junos: 20.4R3-S1.3
# JUNOS OS Kernel 64-bit  [20210909.a3fd70d_builder_stable_11-204ab]
# JUNOS OS libs [20210909.a3fd70d_builder_stable_11-204ab]
# JUNOS OS runtime [20210909.a3fd70d_builder_stable_11-204ab]
# JUNOS OS time zone information [20210909.a3fd70d_builder_stable_11-204ab]
# JUNOS OS libs compat32 [20210909.a3fd70d_builder_stable_11-204ab]
# JUNOS OS 32-bit compatibility [20210909.a3fd70d_builder_stable_11-204ab]
# JUNOS py extensions2 [20211120.090111_builder_junos_204_r3_s1]
# JUNOS py extensions [20211120.090111_builder_junos_204_r3_s1]
# JUNOS py base2 [20211120.090111_builder_junos_204_r3_s1]
# JUNOS py base [20211120.090111_builder_junos_204_r3_s1]
# JUNOS OS vmguest [20210909.a3fd70d_builder_stable_11-204ab]
# JUNOS OS crypto [20210909.a3fd70d_builder_stable_11-204ab]
# JUNOS OS boot-ve files [20210909.a3fd70d_builder_stable_11-204ab]
# JUNOS network stack and utilities [20211120.090111_builder_junos_204_r3_s1]
# JUNOS libs [20211120.090111_builder_junos_204_r3_s1]
# JUNOS libs compat32 [20211120.090111_builder_junos_204_r3_s1]
# JUNOS runtime [20211120.090111_builder_junos_204_r3_s1]
# JUNOS na telemetry [20.4R3-S1.3]
# JUNOS Web Management Platform Package [20211120.090111_builder_junos_204_r3_s1]
# JUNOS qfx modules [20211120.090111_builder_junos_204_r3_s1]
# JUNOS qfx runtime [20211120.090111_builder_junos_204_r3_s1]
# JUNOS probe utility [20211120.090111_builder_junos_204_r3_s1]
# JUNOS common platform support [20211120.090111_builder_junos_204_r3_s1]
# JUNOS qfx platform support [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Openconfig [20.4R3-S1.3]
# JUNOS dcp network modules [20211120.090111_builder_junos_204_r3_s1]
# JUNOS modules [20211120.090111_builder_junos_204_r3_s1]
# JUNOS qfx Data Plane Crypto Support [20211120.090111_builder_junos_204_r3_s1]
# JUNOS daemons [20211120.090111_builder_junos_204_r3_s1]
# JUNOS qfx daemons [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services URL Filter package [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services TLB Service PIC package [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services Telemetry [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services TCP-LOG [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services SSL [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services SOFTWIRE [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services Stateful Firewall [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services RTCOM [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services RPM [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services PCEF package [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services NAT [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services Mobile Subscriber Service Container package [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services MobileNext Software package [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services Logging Report Framework package [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services LL-PDF Container package [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services Jflow Container package [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services Deep Packet Inspection package [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services IPSec [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services IDS [20211120.090111_builder_junos_204_r3_s1]
# JUNOS IDP Services [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services HTTP Content Management package [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services Crypto [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services Captive Portal and Content Delivery Container package [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services COS [20211120.090111_builder_junos_204_r3_s1]
# JUNOS AppId Services [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services Application Level Gateways [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Services AACL Container package [20211120.090111_builder_junos_204_r3_s1]
# JUNOS SDN Software Suite [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Extension Toolkit [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Phone-home [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Packet Forwarding Engine Support (DC-PFE) [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Packet Forwarding Engine Support (M/T Common) [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Juniper Malware Removal Tool (JMRT) [1.0.0+20211120.090111_builder_junos_204_r3_s1]
# JUNOS J-Insight [20211120.090111_builder_junos_204_r3_s1]
# JUNOS jfirmware [20211120.090111_builder_junos_204_r3_s1]
# JUNOS Online Documentation [20211120.090111_builder_junos_204_r3_s1]
# JUNOS jail runtime [20210909.a3fd70d_builder_stable_11-204ab]
# JUNOS FIPS mode utilities [20211120.090111_builder_junos_204_r3_s1]
# Junos host: 20.4R3-S1.3
# JUNOS Host kernel-release [3.14.52-rt50-WR7.0.0.9_ovp]
# JUNOS Host kernel-version [#1 SMP Mon Oct 18 05:48:26 PDT 2021]
# JUNOS Host ex-4300mp platform package [20.4R3-S1.3]
# JUNOS Host ex-4300mp control-plane package [20.4R3-S1.3]
# JUNOS Host ex-4300mp base package [20.4R3-S1.3]
# JUNOS Host ex-4300mp data-plane package [20.4R3-S1.3]
# 
# fpc2:
# --------------------------------------------------------------------------
# Hostname: che-acc1-sw
# Model: ex4300-48t
# Junos: 20.4R3-S1.3
# JUNOS EX  Software Suite [20.4R3-S1.3]
# JUNOS FIPS mode utilities [20.4R3-S1.3]
# JUNOS Crypto Software Suite [20.4R3-S1.3]
# JUNOS Online Documentation [20.4R3-S1.3]
# JUNOS Phone-Home Software Suite [20.4R3-S1.3]
# JUNOS jsd [powerpc-20.4R3-S1.3-jet-1]
# JUNOS SDN Software Suite [20.4R3-S1.3]
# JUNOS EX 4300 Software Suite [20.4R3-S1.3]
# JUNOS Web Management Platform Package [20.4R3-S1.3]
# JUNOS py-base-powerpc [20.4R3-S1.3]
# JUNOS py-base2-powerpc [20.4R3-S1.3]
# JUNOS py-extensions-powerpc [20.4R3-S1.3]
# JUNOS py-extensions2-powerpc [20.4R3-S1.3]
# REST API Software Suite [20.4R3-S1.3]
# 
# fpc3:
# --------------------------------------------------------------------------
# Hostname: che-acc1-sw
# Model: ex4300-48t
# Junos: 20.4R3-S1.3
# JUNOS EX  Software Suite [20.4R3-S1.3]
# JUNOS FIPS mode utilities [20.4R3-S1.3]
# JUNOS Crypto Software Suite [20.4R3-S1.3]
# JUNOS Online Documentation [20.4R3-S1.3]
# JUNOS Phone-Home Software Suite [20.4R3-S1.3]
# JUNOS jsd [powerpc-20.4R3-S1.3-jet-1]
# JUNOS SDN Software Suite [20.4R3-S1.3]
# JUNOS EX 4300 Software Suite [20.4R3-S1.3]
# JUNOS Web Management Platform Package [20.4R3-S1.3]
# JUNOS py-base-powerpc [20.4R3-S1.3]
# JUNOS py-base2-powerpc [20.4R3-S1.3]
# JUNOS py-extensions-powerpc [20.4R3-S1.3]
# JUNOS py-extensions2-powerpc [20.4R3-S1.3]
# REST API Software Suite [20.4R3-S1.3]
":String [NoMethodError]
--------------------------------------------------
/var/lib/gems/3.0.0/gems/oxidized-0.29.0/lib/oxidized/model/outputs.rb:29:in `block in types'
/var/lib/gems/3.0.0/gems/oxidized-0.29.0/lib/oxidized/model/outputs.rb:29:in `map'
/var/lib/gems/3.0.0/gems/oxidized-0.29.0/lib/oxidized/model/outputs.rb:29:in `types'
/var/lib/gems/3.0.0/gems/oxidized-0.29.0/lib/oxidized/output/git.rb:43:in `store'
/var/lib/gems/3.0.0/gems/oxidized-0.29.0/lib/oxidized/worker.rb:65:in `process_success'
/var/lib/gems/3.0.0/gems/oxidized-0.29.0/lib/oxidized/worker.rb:47:in `process'
/var/lib/gems/3.0.0/gems/oxidized-0.29.0/lib/oxidized/worker.rb:16:in `block in work'
/var/lib/gems/3.0.0/gems/oxidized-0.29.0/lib/oxidized/worker.rb:16:in `each'
/var/lib/gems/3.0.0/gems/oxidized-0.29.0/lib/oxidized/worker.rb:16:in `work'
/var/lib/gems/3.0.0/gems/oxidized-0.29.0/lib/oxidized/core.rb:36:in `run'
/var/lib/gems/3.0.0/gems/oxidized-0.29.0/lib/oxidized/core.rb:29:in `initialize'
/var/lib/gems/3.0.0/gems/oxidized-0.29.0/lib/oxidized/core.rb:4:in `new'
/var/lib/gems/3.0.0/gems/oxidized-0.29.0/lib/oxidized/core.rb:4:in `new'
/var/lib/gems/3.0.0/gems/oxidized-0.29.0/lib/oxidized/cli.rb:13:in `run'
/var/lib/gems/3.0.0/gems/oxidized-0.29.0/bin/oxidized:8:in `<top (required)>'
/usr/local/bin/oxidized:25:in `load'
/usr/local/bin/oxidized:25:in `<main>'
--------------------------------------------------

@aschaber1 aschaber1 force-pushed the 2749-comware-issues-with-cut_both-in-0290 branch from e36a210 to bf9ba92 Compare April 14, 2023 11:56
@aschaber1
Copy link
Collaborator Author

Thank you @neilschelly , I'll keep working on it :)

@aschaber1
Copy link
Collaborator Author

I can confirm the error even for comware:

Unfortunately I'm not good enough in ruby to fix this. :(

I have written tests that are able to access .type, hence I'm uncertain why this doesn't work.
I even tried a build where I added using Oxidized::StringRefinements inside lib/oxidized/model/conware.rb to ensure that the reason it's not working is not based on it not inheriting the using from Oxidized::Model.

--------------------------------------------------
2023-04-13 21:54:11 UTC
undefined method `type' for "<correct beginning of config though redacted for GitHub>":String [NoMethodError]
--------------------------------------------------
/var/lib/gems/3.0.0/gems/oxidized-0.29.0/lib/oxidized/model/outputs.rb:25:in `block in type'
/var/lib/gems/3.0.0/gems/oxidized-0.29.0/lib/oxidized/model/outputs.rb:25:in `select'
/var/lib/gems/3.0.0/gems/oxidized-0.29.0/lib/oxidized/model/outputs.rb:25:in `type'
/var/lib/gems/3.0.0/gems/oxidized-0.29.0/lib/oxidized/model/outputs.rb:9:in `type_to_str'
/var/lib/gems/3.0.0/gems/oxidized-0.29.0/lib/oxidized/model/outputs.rb:5:in `to_cfg'
/var/lib/gems/3.0.0/gems/oxidized-0.29.0/lib/oxidized/output/file.rb:25:in `store'
/var/lib/gems/3.0.0/gems/oxidized-0.29.0/lib/oxidized/worker.rb:65:in `process_success'
/var/lib/gems/3.0.0/gems/oxidized-0.29.0/lib/oxidized/worker.rb:47:in `process'
/var/lib/gems/3.0.0/gems/oxidized-0.29.0/lib/oxidized/worker.rb:16:in `block in work'
/var/lib/gems/3.0.0/gems/oxidized-0.29.0/lib/oxidized/worker.rb:16:in `each'
/var/lib/gems/3.0.0/gems/oxidized-0.29.0/lib/oxidized/worker.rb:16:in `work'
/var/lib/gems/3.0.0/gems/oxidized-0.29.0/lib/oxidized/core.rb:36:in `run'
/var/lib/gems/3.0.0/gems/oxidized-0.29.0/lib/oxidized/core.rb:29:in `initialize'
/var/lib/gems/3.0.0/gems/oxidized-0.29.0/lib/oxidized/core.rb:4:in `new'
/var/lib/gems/3.0.0/gems/oxidized-0.29.0/lib/oxidized/core.rb:4:in `new'
/var/lib/gems/3.0.0/gems/oxidized-0.29.0/lib/oxidized/cli.rb:13:in `run'
/var/lib/gems/3.0.0/gems/oxidized-0.29.0/bin/oxidized:8:in `<top (required)>'
/usr/local/bin/oxidized:25:in `load'
/usr/local/bin/oxidized:25:in `<main>'
--------------------------------------------------

@aschaber1
Copy link
Collaborator Author

aschaber1 commented Apr 14, 2023

Got it working @neilschelly. Could you try with the latest commit e75fd27

I, [2023-04-14T12:57:27.642706 #1078]  INFO -- : Configuration updated for /<comware device>
I, [2023-04-14T12:57:34.677381 #1078]  INFO -- : Configuration updated for /<fortios device>

@neilschelly
Copy link
Contributor

Now, I'm getting the cut_both issues with comware again, but the above issues are resolved.

E, [2023-04-14T13:03:47.730719 #1] ERROR -- : IPADDRESS raised NoMethodError with msg "undefined method `cut_both' for "display version
HPE Comware Platform Software
Comware Software, Version 5.20.99, Release 5501P36
Copyright (c) 2010-2018 Hewlett Packard Enterprise Development LP
HP A5500-24G-4SFP HI Switch with 2 interface Slots uptime is 27 weeks, 4 days, 6 hours, 5 minutes

HP A5500-24G-4SFP HI Switch with 2 interface Slots with 2 Processors
1024M   bytes SDRAM
4096K   bytes Nor Flash Memory

512M    bytes Nand Flash Memory
Hardware Version is REV.B
CPLD Version is 003
Bootrom Version is 215
[SubSlot 0] 24GE+4SFP+2SFP PLUS Hardware Version is REV.B
[SubSlot 1] 2 CX4 Hardware Version is REV.A

<SWITCHNAME>":String", IPADDRESS saved

@aschaber1
Copy link
Collaborator Author

aschaber1 commented Apr 14, 2023

@neilschelly apparently I forgot I changed two things at once and only commited once.

So I do need to add them to the Model itself too. please try again. I fixed Junos for you too.

If that works I need to do it to every model..

@neilschelly
Copy link
Contributor

This is working for me now, no errors and the Comware plugin is working correctly.

Thanks so much for your work on this so quickly! I was not going to come up with a solution this clean.

@aschaber1
Copy link
Collaborator Author

Thank you, me neither, it was @ytti who pointed me in the right direction. I'll have to fix all other models and then release 0.29.1 tonight.

module Oxidized
class Model
using Oxidized::StringRefinements
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have to mention Oxidized, as we are also under this namespace, so the search path will hit us. Idiomatically we don't mention it, when we don't have to.

I personally still would prefer Oxidized::String to be module included in Refinements module which refines Strings by including the Oxidized::String module, as in the comware ticket. But this is more matter of taste than anything I can justify.

The justification being, maybe we add refinements to other classes, and then we don't have to change anything, as we already included the Refinements module, which contains not just String but now something else.
And including module instead of listing it directly, because we can have them in separate files cleanly.

Like maybe a refinements.rb including string and any futureType.

And require 'refinements'. using Refinements.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it, and I'll have a go at it, dunno if I can make it though :|

Copy link
Collaborator Author

@aschaber1 aschaber1 Apr 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally still would prefer Oxidized::String to be module included in Refinements module which refines Strings by including the Oxidized::String module, as in the comware ticket. But this is more matter of taste than anything I can justify.

I don't think that's possible. Or I don't know how.
I can create a Refinements Module and put the code there, so we only need that. But I don't think it's possible to "include" Oxidized::String in a Refinements module.

Also I do not believe we can use using Refinements. but we'd have to do using Refinements::StringRefinements.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could do:

module Refinements
  # Use the 'refine' keyword to define refinements for the String class
  refine String do
    [...]
  end

  refine Array do
    [...]
  end
end
class Foobar
  using Refinements
  [...]

and that would allow us to refine String and Array at the same time.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ytti , so i tried to do come as close as possible to your wish. Please let me know if that's acceptable now :)

@ytti
Copy link
Owner

ytti commented Apr 14, 2023

Thank you, me neither, it was @ytti who pointed me in the right direction. I'll have to fix all other models and then release 0.29.1 tonight.

I think we really want to avoid needing to require these in models themselves, and have the refinement come from the parent. Adding boilerplate code in models itself would be undesirable.

I can't quickly find a way to do this to the model subclasses with refinements dynamically, only with monkey patching. So either I'm missing something, or we need boilerplate or we need to just monkey patch String.

It looks like for pre/post we will inherit the refinements, as instance_eval is exception to the rules that stop refinements from being inherited. So there might be a way to make the refinements work in models without boilerplate.
I'm not sure if instance_exec gets the refinements, because that's how we run the cmd block here:
out = instance_exec Oxidized::String.new(out), &block if block

Would need to commit more time to figure this out if refinements without boilerplate is doable.

@aschaber1 aschaber1 force-pushed the 2749-comware-issues-with-cut_both-in-0290 branch 3 times, most recently from 97e321f to 4eee60e Compare April 14, 2023 17:18
@aschaber1
Copy link
Collaborator Author

here's a summary of the change:

  • create a lib/refinements.rb which refines String.
  • add a require refinements in lib/oxidized.rb.
  • add using Refinements to all classes inside lib/oxidized/model/

@ytti
Copy link
Owner

ytti commented Apr 15, 2023

here's a summary of the change:

  • add using Refinements to all classes inside lib/oxidized/model/

I wish we could avoid this. I don't like that we need boiler plate for model makers. Almost feels like outright monkey-patching String is better even with the risks involved, of refinements cannot be inherited or dynamically inserted (I tried, and couldn't find a way).

One option that I think might work, for example in cmd in model.rb be have instance_exec .... block. Before we call this, we may be able to add refinement to the block. Something like this.

old:

def cmd(string, &block)
   ....
end

new:

def cmd(string, &block)
    block.binding.eval("using Refinements")
    ...
end

&block is the code user supplies, here we're getting the binding for the block then evaluating code inside that binding, this should mean as if user had written ``ùsing Refinements``` in the block itself.

@aschaber1
Copy link
Collaborator Author

I understand your concerns, but using refinements already pushed my ruby knowledge way over the limit. I want to help the project but I'll mostly focus on pipelines and tooling.

Hence I suggest let's merge this and fix 0.29.0 by releasing 0.29.1, and then either you or someone else finds another solution.

I check and clean the git commits, so when someone wants to rewrite it, it is going to be a simple git revert of just one commit.

Hope that's okay :)

@aschaber1
Copy link
Collaborator Author

Got feedback from @ytti , will merge and release new patch :)

@aschaber1 aschaber1 force-pushed the 2749-comware-issues-with-cut_both-in-0290 branch 4 times, most recently from 3940d4d to 6324a54 Compare April 20, 2023 15:20
@aschaber1 aschaber1 force-pushed the 2749-comware-issues-with-cut_both-in-0290 branch from 6324a54 to e47d719 Compare April 20, 2023 15:21
@aschaber1 aschaber1 merged commit 3dd0147 into ytti:master Apr 20, 2023
5 checks passed
@aschaber1 aschaber1 deleted the 2749-comware-issues-with-cut_both-in-0290 branch April 20, 2023 15:23
@nicholas-wg2
Copy link

nicholas-wg2 commented May 2, 2023

just wanted to mention that i discovered this breaking change recently because i receive this error:
<IP> raised NoMethodError with msg "undefined method `cut_both' for...

and that's where I found out that something changed, as you mention I have to add using Refinements to each of my custom models. It would be nice to make it clear in release notes and documentation (or automatically include it as previous comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Comware issues with cut_both in 0.29.0
5 participants